Junit 4: "expected" annotation not being processed
I'm seeing an issue with JUnit tests that declare that they will throw an exception,e.g.:
@Test(expected=IllegalArgumentException.class)
public final void testThrowsException() throws Exception {
if(true) {
throw new IllegalArgumentException("Oh man!");
}
}
I would expect this test to pass, but it fails as if I did not have the annotation there. Is there a setting I don't have on, or is this a bug? I'm using 103.190
Please sign in to leave a comment.
This should work. I have hundreds of tests like that in my project. Can you post the stack trace of the failure?
I see what the problem is. The test was originally defined as a Junit 3 test case (extends TestCase). I've removed the inheritance and it works as it should.
Thanks!
Adam
There's a dedicated inspection for that, I think ;)
Good to know!