请帮我在这:单元测试方法从另一个方法调用C#
在这里我需要通过Calling(...)
方法MyAnotherClass
调用此方法Add(...)
。当我Assert
它给出了一个错误。请告诉我路径。
public class MyClass
{
public List<int> number = new List<int>();
public void Add(int a, int b)
{
int c = a + b;
number.Add(c);
}
}
public class MyAnotherClass
{
public void CallingMethod(int c, int d)
{
MyClass mc = new MyClass();
mc.Add(c, d);
}
}
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
MyAnotherClass mac = new MyAnotherClass();
MyClass mc = new MyClass();
mc.Add(2, 3);
Assert.AreEqual(5, mc.number[0]);// **this work fine**
mac.CallingMethod(2, 3);
Assert.AreEqual(5, mc.number[0]);// **but this not**
}
}
感谢
初学者
你试过调试吗?第二个'mc.number [0]'提供了什么值? – ediblecode 2012-01-06 13:51:19