@Test
public void testAdd() {
int i = new Demo().add(2, 5);
assertThat(i, allOf(greaterThan(1) , lessThan(15)));
public void testAdd() {
int i = new Demo().add(2, 5);
assertThat(i, allOf(greaterThan(1) , lessThan(15)));
}
测试过程中出现以下错误:
java.lang.NoSuchMethodError: org.hamcrest.core.AllOf.allOf(Lorg/hamcrest/Matcher;Lorg/hamcrest/Match....
....
原因:
是jar引入顺序导致的,要把hamcrest的jar包放到junit jar包的前面,因为如果hamcrest的jar包放到了junit jar包的后面则程序会默认调用junit jar包里面的 hamcrest core,就会出现上面的问题了