这个问题不是上述问题的重复,我并不是要一个方法来比较实例,而是关于方法assertEqual,以及它的目的是什么。在
assertEqual(a, b)检查a == b是否返回True或False
文件上说Test that first and second are equal. If the values do not compare
equal, the test will fail.
我在一个简单的类上用assertEqual运行三个测试
考试课class Car:
def __init__(self, name):
self.name = name
测试用例
^{pr2}$
结果是F.F
======================================================================
FAIL: test_diff_equal (cartest.CarTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "cartest.py", line 10, in test_diff_equal
self.assertEqual(car1, car2)
AssertionError: !=
======================================================================
FAIL: test_name_equal (cartest.CarTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "cartest.py", line 15, in test_name_equal
self.assertEqual(car1, car2)
AssertionError: !=
----------------------------------------------------------------------
Ran 3 tests in 0.000s
FAILED (failures=2)
是否使用assertEqual检查两个实例是否相同?或者我的设置有什么问题吗?为什么test_name_equal()失败?在