I've found only Hamcrest assertions in Hamcrest project.
Tests in the applications I saw are run with JUnit runner.
Is there a way to run tests with Hamcrest or is Hamcrest not for this?
Hamcrest is not a testing framework, it is an assertions library which tries to make tests more readable.
JUnit 4 (and Hamcrest itself) provides an assertThat()
method which accepts a Hamcrest matcher, for example:
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import org.junit.Test;
public class ATest {
@Test
public void someTest() {
String expected = "...";
String actual = doSomething();
assertThat(actual, is(expected));
}
}
So, a typical usage pattern is:
More details on Hamcrest here and on its use alongside JUnit here.