我有一个从一个集合中获取对象的方法的单元测试。这种情况一直存在,我看不出为什么,所以我在下面创建了一个非常简单的测试来创建2个供应商对象,并测试它们是否相等,以查看我是否可以在我的代码测试中发现问题。但是这个测试再次失败。任何人都能看到或解释为什么?单元测试Assert.AreEqual失败
[TestMethod()]
public void GetSupplierTest2()
{
Supplier expected = new Supplier();
expected.SupplierID = 32532;
expected.SupplierName = "Test 1"
Supplier actual = new Supplier();
actual.SupplierID = 32532;
actual.SupplierName = "Test 1"
Assert.AreEqual(expected, actual);
}
但如果我测试测试通过对象的个别属性...
[TestMethod()]
public void GetSupplierTest2()
{
Supplier expected = new Supplier();
expected.SupplierID = 32532;
expected.SupplierName = "Test 1"
Supplier actual = new Supplier();
actual.SupplierID = 32532;
actual.SupplierName = "Test 1"
Assert.AreEqual(expected.SupplierID , actual.SupplierID);
Assert.AreEqual(expected.SupplierName , actual.SupplierName);
}
您是否可以扩展Equals方法? – suggy1982 2011-06-13 08:48:38