Last active
April 4, 2021 09:03
-
-
Save mehmetcemyucel/cd353046d55a9a41af1aa7ac8823e321 to your computer and use it in GitHub Desktop.
springboot-junit-rule
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
public class ExpectedExceptionTest { | |
@Rule | |
public ExpectedException exp = ExpectedException.none(); | |
@Test | |
public void test() { | |
exp.expect(NullPointerException.class); | |
String value = null; | |
value.split(""); | |
fail(); | |
} | |
@Test | |
public void test2() { | |
exp.expect(ArithmeticException.class); | |
exp.expectMessage("/ by zero"); | |
int val1 = 3, val2 = 0; | |
val1 = val1 / val2; | |
fail(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment