为什么assertEquals()参数的顺序为(预期的,实际的)? [英] Why are assertEquals() parameters in the order (expected, actual)?

查看:337
本文介绍了为什么assertEquals()参数的顺序为(预期的,实际的)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么这么多的assertEquals()或类似函数将期望值作为第一个参数,而将实际值作为第二个参数?
这对我来说似乎是违反直觉的,所以这种不正常的顺序是否有特定的原因?

Why do so many assertEquals() or similar function take the expected value as first parameter and the actual one as second ?
This seems counter-intuitive to me, so is there a particular reason for this unusual order ?

推荐答案

因为作者有50%的机会符合您的直觉.

Because the authors had a 50% chance of matching your intuition.

由于其他重载

assertWhatever(explanation, expected, actual)

作为您所了解的部分的解释与所期望的(即您所知道的,而不是实际的)相吻合,而不是您在编写代码时不知道的实际情况.

And the explanation, which is part of what you know, goes with the expected, which is what you know, as opposed to the actual, which you don't know at the time you write the code.

这篇关于为什么assertEquals()参数的顺序为(预期的,实际的)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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