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