JUnit 4 Tutorial 2 – Expected Exception Test
Written on
May 18, 2009 at 2:36 pm by
mkyong
The “exception testing” means what exception throw from the unit test.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | import org.junit.*; /** * JUnit Expected Exception Test * @author mkyong * */ public class JunitTest2 { @Test(expected = ArithmeticException.class) public void divisionWithException() { int i = 1/0; } } |
Result
Unit test marked success

