Created
January 27, 2015 17:41
-
-
Save clicman/2e74e47f464b19fbbc12 to your computer and use it in GitHub Desktop.
Handle suite events in testStarted/finished
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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