“是”是指在 JUnit 4 断言中
之间有语义差异吗
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
文档说明了一切:
装饰另一个匹配器,保留行为,但允许测试稍微更具表现力。
例如。 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.
据我所知,它们是等效的。 “
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.