我正在尝试在 VS 2012 上学习单元测试并尝试了这个:
public class Calculator
{
public double substraction(double num1, double num2)
{
return num1 - num2;
}
}
我的测试课在这里:
[TestClass]
public class UnitTest1
{
[TestMethod]
public void calc_substract()
{
var calculator = new Calculator();
Assert.AreEqual<double>(calculator.substraction(5.3, 1.1), 4.2);
}
}
给出这个错误:
Test Name: calc_substract
Test FullName: MyUnitTest.UnitTest1.calc_substract
Test Source: d:\Users\...
Test Outcome: Failed
Test Duration: 0:00:00,0068363
**Result Message: Assert.AreEqual failed. Expected:<4,2>. Actual:<4,2>.**
如您所见,值相同但测试失败。你知道为什么吗?