I'm using JUnit 4.11.
Eclipse Version: Luna Service Release 2 (4.4.2)
I need do the exception test. The code maybe like this:
// src code
public void myMethod throws MyException {
...
throw new MyException(msg);
...
}
// test code
@Test (expected = MyException.class)
public void testMyMethod() {
try {
myMethod();
fail();
} catch (MyException e) {
assertEquals(expectedStr, e.getMessage());
}
}
But the test always fail, where am i wrong?