Hamcrest
Hamcrest 사용 이유
Hamcrest Assertion 예시 1
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
public class HelloHamcrestTest {
@DisplayName("Hello Junit Test using hamcrest")
@Test
public void assertionTest1() {
String expected = "Hello, JUnit";
String actual = "Hello, World";
assertThat(actual, is(equalTo(expected))); // Hamcrest Matcher 이용
}
}
> 출력
> Expected: is "Hello, JUnit"
> but: was "Hello, World"