How to Test Protected Static method in Abstract Class using JustMock

2 posts, 0 answers
  1. regula
    regula avatar
    1 posts
    Member since:
    Dec 2014

    Posted 23 Dec 2014 Link to this post

    How to Test Protected Static method in Abstract Class using JustMock 
  2. Stefan
    Admin
    Stefan avatar
    198 posts

    Posted 24 Dec 2014 Link to this post

    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.

     
  3. DevCraft R3 2016 release webinar banner
Back to Top