【发布时间】:2012-10-22 15:12:42
【问题描述】:
[Test]
public void testMultiplication()
{
var five=new Dollar(5);
Assert.AreEqual(new Dollar(10), five.times(2));
Assert.AreEqual(new Dollar(15), five.times(3));
}
美元类
public class Dollar
{
private int amount;
public Dollar(int amount)
{
this.amount = amount;
}
public Dollar times(int multiplier)
{
return new Dollar(amount * multiplier);
}
public bool equals(Object theObject)
{
Dollar dollar = (Dollar) theObject;
return amount == dollar.amount;
}
}
在线 Assert.AreEqual(new Dollar(10), Five.times(2));测试失败并出现错误:
预期:TDDbooks.Dollar
但是是:TDDbooks.Dollar
【问题讨论】:
-
旁白:为什么不实现运算符重载?
-
看起来可能是程序集版本问题;您是否可能有两个版本的程序集实现
TDDbooks.Dollar已加载?
标签: c# unit-testing nunit