Unit testing C# protected methods

后端 未结 6 1223
再見小時候
再見小時候 2020-12-23 15:39

I come from the Java EE world but now I\'m working on a .Net project. In Java when I wanted to test a protected method it was quite easy, just having the test class with the

6条回答
  •  醉话见心
    2020-12-23 16:21

    You can expose the protected methods in a new class that inherits the class you want to test.

    public class ExposedClassToTest : ClassToTest
    {
        public bool ExposedProtectedMethod(int parameter)
        {
            return base.ProtectedMethod(parameter);
        }
    }
    

提交回复
热议问题