The old way: try
-fail
-catch
public void testDivisionByZero() {
try {
int n = 2 / 0;
fail("Divided by zero!");
}
catch (ArithmeticException success) {
assertNotNull(success.getMessage());
}
}
The new way: @Test(expected=class)
@Test(expected=ArithmeticException.class) public void divideByZero() {
int n = 2 / 0;
}
Old way is still necessary for testing exception messages and such