有没有像 assertThat(a, lessThan(b));
这样的东西?我目前正在使用Junit 4.8.1,但我找不到lessThan。相反,我必须使用assertTrue(a < b)
,但这样做的缺点是它不会在测试日志中打印两个数字。
有没有像 assertThat(a, lessThan(b));
这样的东西?我目前正在使用Junit 4.8.1,但我找不到lessThan。相反,我必须使用assertTrue(a < b)
,但这样做的缺点是它不会在测试日志中打印两个数字。
您尝试过使用JUnit + Hamcrest吗?看这篇博客文章的一些示例——它几乎和你发布的内容完全一样:
JUnit 4展示 - assertThat和Hamcrest Matchers
或者,还有JUnit-addons项目中的ComparableAssert。
Matchers
类似乎不随Junit使用的Hamcrest一起提供。添加Hamcrest-library作为附加依赖项,使我获得了所需的Matchers
类。 - Raystormimport static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
assertThat(foo, Matchers.lessThan(bar));