Skip to content

Instantly share code, notes, and snippets.

@su-kun1899
Created September 4, 2016 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save su-kun1899/316be9d77db3eeae898042f91002f49a to your computer and use it in GitHub Desktop.
Save su-kun1899/316be9d77db3eeae898042f91002f49a to your computer and use it in GitHub Desktop.
JUnitでの例外テストの書き方 ref: http://qiita.com/su-kun1899/items/5c9f0294a7de1986e542
@Test(expected = SampleException.class)
public void throwsSampleException() {
// do something
}
@Test
public void throwsSampleException() {
try {
// do something
...
fail();
} catch (SampleException expected) {
assertThat(expected.getMessage(), equalTo("exception message"));
}
}
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void exceptionRule() {
thrown.expect(SampleException.class);
thrown.expectMessage("exception message");
// do something
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment