Junit 使用hamcrest的Matcher找不到的问题(比如greaterThan)

问题:

用junit在进行单元测试的时候,使用assertThat方法,发现hamcrest的greaterThan等方法无法识别【说是没有定义】,而且无法静态引用到Matchers类【import static org.hamcrest.Matchers.*;】

junit版本: 4.12

hamcrest版本:hamcrest-core-1.3

 

原因:

后来发现原因是因为junit默认只会依赖hamcrest-core-1.3包【我用maven构建的项目管理的jar包】,而实际上hamcrest还有一个hamcrest-library.jar用来放置很多工具

 

解决:

显式引入hamcrest-library-1.3.jar包,maven中添加依赖:


	org.hamcrest
	hamcrest-library
	1.3

 

你可能感兴趣的:(Java,Junit)