简体   繁体   English

JUnit 4断言中的“是”

[英]The “is” in JUnit 4 assertions

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? 这里还有其他考虑事项吗?

Documentation says it all: 文档说明了一切:
Decorates another Matcher, retaining the behavior but allowing tests to be slightly more expressive. 装饰另一个Matcher,保留其行为,但允许测试更具表现力。
eg. 例如。 assertThat(cheese, equalTo(smelly)) assertThat(奶酪,equalTo(臭))
vs assertThat(cheese, is(equalTo(smelly))) vs assertThat(奶酪,is(equalTo(臭)))

http://www.junit.org/apidocs/org/hamcrest/core/Is.html http://www.junit.org/apidocs/org/hamcrest/core/Is.html
In other words, you're on the right track. 换句话说,您走在正确的轨道上。

They are equivalent, as far as I'm aware. 据我所知,它们是等效的。 The " Is " matcher just passes through to the contained matcher. Is ”匹配器只是传递到所包含的匹配器。 It seems it's there to add readability, and perhaps backwards compatibility. 似乎可以增加可读性,甚至可以向后兼容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM