手抄报 安全手抄报 手抄报内容 手抄报图片 英语手抄报 清明节手抄报 节约用水手抄报

如何测试私有 Private/Internal 方法

时间:2024-10-14 07:21:07

1、添加测试方法 TestMethod

2、初始化 PrivateObject(测试实例方法),PrivateType ( 测试私有方法)[TestMethod] public void TestPrivateAdd() { PrivateObject po = new PrivateObject(new Calculate()); Assert.AreEqual(po.Invoke("Add", 1, 2), 3); }

3、针对Internal修饰的一样可以使用 PrivateObject/PrivateType[TestMethod] public void TestInternalStaticAdd() { PrivateType po = new PrivateType(typeof(Calculate)); Assert.AreEqual(po.InvokeStatic("AddStatic", 1, 2), 3); }

© 手抄报圈