Skip to content

Instantly share code, notes, and snippets.

@clicman
Created January 27, 2015 17:41
Show Gist options
  • Save clicman/2e74e47f464b19fbbc12 to your computer and use it in GitHub Desktop.
Save clicman/2e74e47f464b19fbbc12 to your computer and use it in GitHub Desktop.
Handle suite events in testStarted/finished
import org.junit.internal.requests.ClassRequest;
import org.junit.runner.Description;
import org.junit.runner.Request;
import org.junit.runner.notification.RunListener;
import org.junit.runner.notification.RunNotifier;
class Runner {
public void run() {
RunNotifier notifer = new RunNotifier();
notifer.addFirstListener(new RunListener() {
@Override
public void testStarted(Description description) throws Exception {
if (description.isSuite()) {
System.out.println("Start Suite:" + description.getDisplayName());
} else {
System.out.println("Start test:" + description.getDisplayName());
}
}
@Override
public void testFinished(Description description) throws Exception {
if (description.isSuite()) {
System.out.println("Finish Suite:" + description.getDisplayName());
} else {
System.out.println("Finish test:" + description.getDisplayName());
}
}
});
Request request = new ClassRequest(NewTestSuite.class);
notifer.fireTestStarted(request.getRunner().getDescription());
request.getRunner().run(notifer);
notifer.fireTestFinished(request.getRunner().getDescription());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment