.net unit testing 中 assert.equal 不支持自定义的类么??永远返回false???
怎么办啊?

解决方案 »

  1.   

    是不是要重载你自定义类的equal()方法啊?
      

  2.   

    我确实是在想这个问题!! 就是assert.equal 到底是如何来判断两个实例是否相等呢????如果实例的类是复杂类,其中包含很多小类的话又如何处理???
    但是在工程中并不需要给每个复杂类都重写equal方法阿,那样不要死人的阿?所以如果是这样的话,unit testing还有啥必要啊?最简单的代码,随便生成一个uint testing 模块,然后里面         [TestMethod()]
            public void addTest()
            {
                //TestClass1 target = new TestClass1();            //int a = 0; // TODO: Initialize to an appropriate value            //int b = 0; // TODO: Initialize to an appropriate value            //int expected = 0;
                //int actual = 0;            //actual = target.add(a, b);            TestClass1 expected = new TestClass1();
                TestClass1 actual = new TestClass1();
                Assert.AreEqual(expected, actual, "ConsoleApplication.TestClass1.add did not return the expected value.");
                //Assert.Inconclusive("Verify the correctness of this test method.");
            }这样永远是false. 但是如果用VS内置的类就返回true。  难道Assert.AreEqual不支持递归判断相等么?唉...那样不是太弱了阿
      

  3.   

    自定义的类必须重载equal方法的,不然比较两个引用,肯定是不同的。
      

  4.   

    assert.equal 就是断言assert的静态方法,不用重载了吧
    asssert就是值的比较,如果你要比较两个对象的话,需要重载了
      

  5.   

    那么是不是说对于复杂的类,根本没办法去做unit testing??? 
      

  6.   

    或者用多个Assert语句去把类里的值进行比较