How to Test Protected Static method in Abstract Class using JustMock
1 Answer, 1 is accepted
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.