Created
July 1, 2012 11:32
-
-
Save ahirata/3028071 to your computer and use it in GitHub Desktop.
Using junit ExpectedException instead of @test(expected=SomeException.class)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package atarih.lab; | |
| import org.junit.Rule; | |
| import org.junit.Test; | |
| import org.junit.rules.ExpectedException; | |
| public class TestWithRule { | |
| @Rule | |
| public ExpectedException expectedException = ExpectedException.none(); | |
| @Test | |
| public void expectedException() { | |
| expectedException.expect(RuntimeException.class); | |
| expectedException.expectMessage("my"); | |
| expectedException.expectMessage("my.exception"); | |
| new Foo().bar(); | |
| } | |
| public static class Foo { | |
| public void bar() { | |
| throw new IllegalArgumentException("my.exception"); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment