Unit testing C# protected methods

后端 未结 6 1226
再見小時候
再見小時候 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:39

    You can inherit the class you are testing on your test class.

    [TestClass]
    public class Test1 : SomeClass
    {
        [TestMethod]
        public void MyTest
        {
            Assert.AreEqual(1, ProtectedMethod());
        }
    
    }
    

提交回复
热议问题