I want to implement exception checking (for example, in JUnit 4) using JUnit 3. For example, I would like to write such tests as follows:
public void testMyExceptionThrown() throws Exception {
shouldThrow(MyException.class);
doSomethingThatMightThrowMyException();
}
This should succeed if and only if a MyException is thrown. There is an ExceptionTestCase class in JUnit, but I want something that each test * method may decide to use or not to use. What is the best way to achieve this?
source
share