什么是 testunit 或其他 nunit 样式框架的良好失败消息? [英] What makes a good failure message for testunit or other nunit style frameworks?

查看:40
本文介绍了什么是 testunit 或其他 nunit 样式框架的良好失败消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Ruby 的测试/单元和其他类似 nunit 风格的框架中,什么是好的失败信息?

In Ruby's test/unit, and other such nunit style frameworks, what makes a good failure message?

失败消息是否应该仅仅描述期望值与期望值不匹配的原因?

Should the failure message merely describe how the expected value does not match the expected value?

assert_match("hey", "hey this is a test", "The word does not exist in the string")

它是否应该描述您期望发生的事情?

Should it describe what you expected to happen?

assert_match("hey", "hey this is a test", "I expected hey to be in the string")

它是否应该描述您希望这种行为发生的原因?

Should it describe why you wanted the behavior to happen?

assert_match("hey", "hey this is a test", "Program should provide a greeting")

它是否应该描述您认为测试可能会失败的原因?

Should it describe why you thought the test may fail?

assert_match("konnichiwa", "konnichiwa this is a test",
  "Program failed to use supplied i18n configuration")

测试方法的名称和测试用例的名称中是否也应该存在有关测试的信息?

Should information about tests also exist in the name of the test method, and in the name of the test case?

这是基于 Ruby测试/单元", 如何在断言中显示消息

推荐答案

失败消息应该为失败消息添加上下文.因此,任何让您不必深入测试代码以了解失败内容的方法.

the failure message is supposed to add context to the failure message. So anything that saves you having to drill into the test code to know what failed.

所以如果 [method name, expected, actual] 集足以满足上述目的,您可以跳过失败消息.如果您需要更多信息,请添加可选的失败消息.

So if the [method name, expected, actual] set is adequate for the above purpose, you can skip the failure message. If you need more information, then you add the optional failure message.

例如预期为真但为假,没有告诉我任何事情.

e.g. Expected true but was false, doesn't tell me anything.

您可以使用失败消息,以便返回值应仅包含 10 的倍数.预期为真但为假

You can use a failure message so that Return value should contain only multiples of 10. Expected true but was false

您可以先尝试使用更具描述性的匹配器.所以失败读取 预期所有项目都可以被 10 整除,但 [10,20,35,40] 确实如此.

You can first try to use more descriptive matchers. So that failures read Expected all items to be divisible by 10 but was [10,20,35,40] does.

我个人更喜欢匹配器......使用失败消息作为最后的手段.(因为像评论一样,它会衰减.如果您更改检查,您需要纪律以确保更新失败消息.)

Personally I prefer matchers... use failure messages as the last resort. (because like comments, it decays. You need discipline to ensure that the failure message is updated if you change the check.)

这篇关于什么是 testunit 或其他 nunit 样式框架的良好失败消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆