gpt4 book ai didi

ruby - 什么是 testunit 或其他 nunit 风格框架的良好失败消息?

转载 作者:数据小太阳 更新时间:2023-10-29 07:36:49 25 4
gpt4 key购买 nike

在 Ruby 的 test/unit 和其他类似 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

最佳答案

失败消息应该为失败消息添加上下文。因此,您不必深入研究测试代码以了解失败的原因。

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

例如预期为真但为假,什么也没告诉我。

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

您可以先尝试使用更具描述性的匹配器。所以失败读取 Expected all items to be divisible by 10 but was [10,20,35,40] does。

我个人更喜欢匹配器...将失败消息作为最后的手段。 (因为像注释一样,它会衰减。您需要纪律以确保在更改检查时更新失败消息。)

关于ruby - 什么是 testunit 或其他 nunit 风格框架的良好失败消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8468410/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com