This is a migrated thread and some comments may be shown as answers.

How to Test Protected Static method in Abstract Class using JustMock

1 Answer 54 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
regula
Top achievements
Rank 1
regula asked on 23 Dec 2014, 11:23 AM
How to Test Protected Static method in Abstract Class using JustMock 

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 24 Dec 2014, 06:51 AM
Hi Regula,

Protected members can be called in tests using the PrivateAccessor class:
public abstract class MyClass
{
    protected static void MyMethod()
    {
        // ...
    }
}

[TestMethod]
public void Test()
{
    // Arrange dependencies
    // ...
    
    // Act
    var acc = Mock.NonPublic.MakeStaticPrivateAccessor(typeof(MyClass));
    acc.CallMethod("MyMethod");
    
    // Assert
    // ...
}

Regards,
Stefan
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
General Discussions
Asked by
regula
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or