为什么我应该使用 assert_equal 而不是在 minitest 中使用相等运算符断言?

Why should I use assert_equal instead of just assert with an equal operator in minitest?

我真的很喜欢 Minitest,它很简单,但我不明白为什么我应该使用 assert_equal 而不是 assert== 运算符。

如果我查看 Implementationassert_equal 方法与我所说的等于运算符完全相同。

为什么中间需要这一步而不是直接使用呢?

我还认为它不会因为那里的 equal 而更具可读性,因为 == 是不言自明的。

通常当您更喜欢清晰的失败消息时,您需要 assert_equal

当你写 assert a == b 并且测试由于任何原因失败时,消息只会说一些类似于 Assertion failed 的内容。 另一方面,如果您使用 assert_equal a, b,失败将显示一条消息,如 Expected a to be equal to b,它为您提供有关测试失败原因的更多详细信息。

我认为这只是一个选择问题,对我来说 assert_equal 看起来比使用 ==

更具可读性
assert_equal expect, actual