西秀岭

导航

C# 中如何进行私有(private)函数测试

  public class User
    {
        public string Name;
        public string Id;
   
private string GetID() { return Id; } } [TestClass()] public class UserTests { [TestMethod()] public void ToStringTest() { User user= new User(); user.Id = "10"; PrivateObject pObj = new PrivateObject(user); var ret = (string)pObj.Invoke("GetID", null); Assert.AreEqual("10", ret); } }

  

posted on 2020-11-11 10:09  西秀岭  阅读(1134)  评论(0编辑  收藏  举报