Junit Assert

JUnit 단언 스타일

하나만 선택하는 것이 좋다

햄크레스트 매처

Hamcrest 2.2 API

assertTrue(account.hasPositiveBalance());

assertTrue(account.getBalance() > initialBalance);
assertThat(account.getBalance(), equalTo(100));

assertThat(account.getBalance() > 0, is(true));
assertThat(new String[] {"a", "b"}, equalTo(new String[] {"a", "b"}));

assertTrue(account.getName().startsWith("xyz"));

// 여러 조건
assertThat(account.getName(), allOf(startsWith("my"), endsWith("acct")));
assertThat(account.getName(), anyOf(startsWith("my"), endsWith("loot")));

assertThat(account.getName(), not(equalTo("plunderings")));

// null 체크
assertThat(account.getName(), is(not(nullValue())));
assertThat(account.getName(), is(notNullValue()));