Skip to content

Instantly share code, notes, and snippets.

@rschumm
Created June 1, 2012 08:30
Show Gist options
  • Save rschumm/2850334 to your computer and use it in GitHub Desktop.
Save rschumm/2850334 to your computer and use it in GitHub Desktop.
JUnit excepted Exception
@Rule
public ExpectedException thrown = ExpectedException.none();
//Test, der eine Exception mit der Massage "bla" erwartet.
@Test
public void testNothingFoundServer() throws Exception {
thrown.expectMessage("bla");
thrown.expect(FakeUnmarshallNothingFoundException.class);
codeDerKnallt();
}
@u2ix
Copy link

u2ix commented Jun 1, 2012

Or simpler:

@Test(expected=FakeUnmarshallNothingFoundException.class)

@rschumm
Copy link
Author

rschumm commented Jun 1, 2012

nein, die Idee war, die erwartete Exception eben auch auf die Message zu prüfen, nicht nur deren Auftreten.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment