I have a small junit4 test that expect an exception.
this the code:
@Test(expected = EntityVide.class)
public void testPing() throws Exception {
System.out.println("ping");
int in = 0;
int expResult = 1;
int result = instance.ping(in);
}
When i run the test it showed as a failed one .
I have already added @RunWith(JUnit4ClassRunner.class) but nothing changed .
I’m using netbeans 7.0 and junit 4.
Thanks .
expectedattribute of @Test annotation is for expected exceptions. Sometimes you want your test to throw exception of certain type. In 3.* version of JUnit you had to writetry/catchblock yourself. In Junit 4 you can mark this test with annotation.Your test does not throw exception, so it fails because you said that you are expecting exception of type
EntityVide. Remove this attribute and useAssert.assertEquals()to validate your result.