datastructure = {
frame:"test"
position:
{
x: 1,
y: 2,
}
orientation:
{
w: 1.23,
z: 2.24,
}
}
我有自定义数据结构。我需要做一个assertAlmostEqual(a, b)
。但是上述数据结构没有- (subtract)
运算符重载,因此assertAlmostEqual
不起作用
我可以像在matchers中一样在unittest.TestCase
中编写匹配器吗?
例如,我想编写assertAlmostEqualCustom
答案 0 :(得分:1)
我可以像在gmock匹配器中一样在unittest.TestCase中编写匹配器吗?
当然可以,许多项目已经使用了从YourTestCase
继承的自己的unittest.TestCase
,例如将使用class TestDataStrut(YourTestCase)
代替class TestDataStruct(unittest.TestCase)
。
如果必须在大型项目中经常使用特定的断言,则必须自己执行。