1 assertThat(8, greaterThan(5));
2 assertThat(8, lessThan(10));
3 assertThat(8, allOf(lessThan(10), greaterThan(5)));
前面两句测试都通过,加上第三句就没通过,报java.lang.NoSuchMethodError,可是 allOf明明就是有的方法呀!包已经引入了(import static org.junit.Assert.*;
import static org.hamcrest.Matchers.*;
import org.junit.Test;)
------解决方案--------------------------------------------------------
- Java code
import static org.junit.Assert.assertThat; // junit-dep-4.10.jarimport static org.hamcrest.CoreMatchers.allOf; // hamcrest-core-1.2.1.jarimport static org.hamcrest.Matchers.lessThan; // hamcrest-library-1.2.1.jarimport static org.hamcrest.Matchers.greaterThan; // hamcrest-library-1.2.1.jar