I made my own JUnit-Runner by implementing org.junit.runner.Runner
, so that I can run my UnitTests with them using the @RunWith
-Annotation.
It lookes somewhat like this:
public class MyRunner extends Runner {
private Context myContext;
myContext.init();
private final BlockJUnit4ClassRunner runner;
public MyRunner(final Class<?> clazz) throws InitializationError {
myContext = new Context();
runner = new BlockJUnit4ClassRunner(clazz);
}
@Override
public void run(final RunNotifier notifier) {
runner.run(notifier);
}
@Override
public Description getDescription() {
return runner.getDescription();
}
public void filter(final Filter filter) throws NoTestsRemainException {
runner.filter(filter);
}
}
To clean up resources, I have to shut down MyContext
by calling MyContext.close()
. Where should I invoke this so that my resources are cleand up after the tests have run?