Search code examples
javaunit-testingtestingjunitjunit4

JUnitCore Stopping


I want to stop/destroy a running JUnitCore, which is started with

JUnitCore.run(Request.aClass(ClassToRun));

Like pleaseStop() on the RunNotifier.

Any ideas?

http://junit.sourceforge.net/javadoc/org/junit/runner/package-summary.html


Solution

  • I want to provide another simple solution to stop a JUnitCore:

    JUnitCore jUnitCore = new JUnitCore();
    Field field = JUnitCore.class.getDeclaredField("fNotifier");
    field.setAccessible(true);
    RunNotifier runNotifier = (RunNotifier) field.get(jUnitCore);
    runNotifier.pleaseStop();
    

    Credits to Matthew Farwell who transfered my idea into code.