使用assertThat,项目要引用以下jar包
junit-4.12.jar
hamcrest-core-1.3.jar
hamcrest-libriry-1.3.jar
pom.xml
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
Test1.java
package test.cms;
//import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
//import static org.junit.Assert.*;
import org.junit.Test;
public class Test1 {
@Test
public void test() {
//fail("Not yet implemented");
assertThat(1, greaterThan(0));
}
}
如果报错找不方法
The method assertThat(int, int) is undefined for the type Test1
The method greaterThan(int) is undefined for the type Test1
引入类即可
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
参考: