是什么让testunit或其他nunit样式框架成为一个好的失败消息?
在Ruby的测试/单元和其他类似的nunit样式框架中,什么是一个好的失败消息?
失败消息是否仅描述预期值与预期值的匹配程度如何?
assert_match("hey", "hey this is a test", "The word does not exist in the string")
它应该描述你预期会发生什么吗?
assert_match("hey", "hey this is a test", "I expected hey to be in the string")
它应该描述为什么你希望这种行为发生吗?
assert_match("hey", "hey this is a test", "Program should provide a greeting")
它应该描述您认为测试可能失败的原因吗?
assert_match("konnichiwa", "konnichiwa this is a test", "Program failed to use supplied i18n configuration")
是否应该在测试方法的名称和测试用例的名称中存在有关测试的信息?
这基于Ruby“test / unit”,如何在断言中显示消息
失败消息应该为失败消息添加上下文。 所以任何可以节省你不得不钻进测试代码以了解失败的东西。
因此,如果[方法名称,预期,实际]设置足以满足上述目的,则可以跳过失败消息。 如果您需要更多信息,则添加可选的失败消息。
例如, Expected true but was false
,并没有告诉我任何事情。
您可以使用失败消息,以便Return value should contain only multiples of 10. Expected true but was false
您可以先尝试使用更具描述性的匹配器。 因此,失败读取Expected all items to be divisible by 10 but was [10,20,35,40]
。
我个人更喜欢匹配器…使用失败消息作为最后的手段。 (因为像评论一样,它会衰减。如果更改支票,您需要遵守规则以确保更新失败消息。)