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);
      }
  }

 

 

出处:https://www.cnblogs.com/xixiuling/p/13957259.html

posted on 2022-05-20 20:26  jack_Meng  阅读(421)  评论(0编辑  收藏  举报

导航