Junit exception test

Posted by Prithis on Stack Overflow See other posts from Stack Overflow or by Prithis
Published on 2010-03-17T12:14:22Z Indexed on 2010/03/17 12:21 UTC
Read the original article Hit count: 313

Filed under:
|

I have two tests to check the expected exception throw. I am using Junit 4 and has following syntax.

@Test(expected=IllegalArgumentException.class)
public void testSomething(){
..........
}

One of the tests fail even though IllegalArgumentException is thrown and the other passes. Any idea whats missing?? I modified the test which is failing to following and it passes.

public void testSomething(){
 try{
  ............ //line that throws exception
  fail();
 }catch(IllegalArgumentException e) {
 }
} 

© Stack Overflow or respective owner

Related posts about junit4

Related posts about java