“是”是指在 JUnit 4 断言中

发布于 2024-08-31 05:03:41 字数 208 浏览 3 评论 0原文

之间有语义差异吗

assertThat(object1, is(equalTo(object2)));

写作和写作

assertThat(object1, equalTo(object2)));

?如果没有,我更喜欢第一个版本,因为它读起来更好。这里还有其他考虑吗?

Is there any semantic difference between writing

assertThat(object1, is(equalTo(object2)));

and writing

assertThat(object1, equalTo(object2)));

? If not, I would prefer the first version, because it reads better. Are there any other considerations here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

叹倦 2024-09-07 05:03:41

文档说明了一切:
装饰另一个匹配器,保留行为,但允许测试稍微更具表现力。
例如。 assertThat(奶酪, equalTo(臭))
与assertThat(cheese, is(equalTo(smelly)))

http://www.junit.org/apidocs/org/hamcrest/core/Is.html
换句话说,你走在正确的道路上。

Documentation says it all:
Decorates another Matcher, retaining the behavior but allowing tests to be slightly more expressive.
eg. assertThat(cheese, equalTo(smelly))
vs assertThat(cheese, is(equalTo(smelly)))

http://www.junit.org/apidocs/org/hamcrest/core/Is.html
In other words, you're on the right track.

独行侠 2024-09-07 05:03:41

据我所知,它们是等效的。 “Is”匹配器只是传递到包含的匹配器。看起来它是为了增加可读性,也许还有向后兼容性。

They are equivalent, as far as I'm aware. The "Is" matcher just passes through to the contained matcher. It seems it's there to add readability, and perhaps backwards compatibility.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文