扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
namespace ClassLibrary1{ public class DivisionClass{ private int Divide_private(int numerator, int denominator){ return numerator / denominator; } } } |
using Microsoft.VisualStudio.TestTools.UnitTesting; namespace TestProject1{ [System.Diagnostics.DebuggerStepThrough()] [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TestTools.UnitTestGeneration", "1.0.0.0")] internal class BaseAccessor { protected Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject m_privateObject; protected BaseAccessor(object target, Microsoft.VisualStudio.TestTools.UnitTesting.PrivateType type) { m_privateObject = new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(target, type); } protected BaseAccessor(Microsoft.VisualStudio.TestTools.UnitTesting.PrivateType type) : this(null, type) {} internal virtual object Target { get { return m_privateObject.Target; } } public override string ToString() { return this.Target.ToString(); } public override bool Equals(object obj) { if (typeof(BaseAccessor).IsInstanceOfType(obj)) { obj = ((BaseAccessor)(obj)).Target; } return this.Target.Equals(obj); } public override int GetHashCode() { return this.Target.GetHashCode(); } } [System.Diagnostics.DebuggerStepThrough()] [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TestTools.UnitTestGeneration", "1.0.0.0")] internal class ClassLibrary1_DivisionClassAccessor : BaseAccessor { protected static Microsoft.VisualStudio.TestTools.UnitTesting.PrivateType m_privateType = new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateType(typeof(global::ClassLibrary1.DivisionClass)); internal ClassLibrary1_DivisionClassAccessor(global::ClassLibrary1.DivisionClass target) : base(target, m_privateType) {} internal int Divide_private(int numerator, int denominator) { object[] args = new object[] { numerator, denominator}; int ret = ((int)(m_privateObject.Invoke("Divide_private", new System.Type[] { typeof(int), typeof(int)}, args))); return ret; } } } |
[DeploymentItem("ClassLibrary1.dll")] [TestMethod()] public void Divide_privateTest() { DivisionClass target = new DivisionClass(); TestProject1.ClassLibrary1_DivisionClassAccessor accessor = new TestProject1.ClassLibrary1_DivisionClassAccessor(target); int numerator = 4; int denominator = 0; int expected = 0; int actual; actual = accessor.Divide_private(numerator, denominator); Assert.AreEqual(expected, actual, "ClassLibrary1.DivisionClass.Divide_private 未返回所需的值。"); Assert.Inconclusive("验证此测试方法的正确性。"); } |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者