22. Four-Phase Test
@Test
public void hoge() {
Hoge sut = new Hoge();
String actual = sut.hoge();
assertThat(actual, is("fuga"));
}
フェーズの間を
1行空けるとかsetup
exercise
verify
構造がわかると読みやすくなる
37. Matcherの使い方
assertThat(today, is(dateOf(2013, 2, 3)));
java.lang.AssertionError:
Expected: is "2013/02/03"
but: "2013/07/31"
at org.hamcrest.MatcherAssert.assertThat(MatcherAssert
at org.junit.Assert.assertThat(Assert.java:865)
at org.junit.Assert.assertThat(Assert.java:832)
at JUnit4Test.hoge(JUnit4Test.java:24)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
describeMismatchで編集可
describeToで編集可
44. modern Exception Test
@Rule
public ExpectedException thrown =
ExpectedException.none();
@Test
public void hoge() {
thrown.expect(NullPointerException.class);
thrown.expectMessage("ぬるぽ");
sut.hoge();
}