是什么让testunit或其他nunit样式框架成为一个好的失败消息?

时间:2011-12-11 23:33:35

标签: ruby unit-testing nunit testunit

在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" , how do I display the messages in asserts

1 个答案:

答案 0 :(得分:2)

失败消息应该为失败消息添加上下文。所以任何可以节省你不得不钻进测试代码以了解失败的东西。

因此,如果[方法名称,预期,实际]设置足以满足上述目的,则可以跳过失败消息。如果您需要更多信息,请添加可选的失败消息。

e.g。 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]的失败确实如此。

我个人更喜欢匹配者...使用失败消息作为最后的手段。 (因为像评论一样,它会衰减。如果你改变支票,你需要遵守规则以确保更新失败信息。)