Remove listeners after suite completes in RestTestSuiteRunner

We need to remove the reproduce info printer after the suite
returns otherwise it might print a bogus line if a subsequent
non-rest test fails. The `RunNotifier` is used across suites in
the same JVM and the listener sticks to it.
This commit is contained in:
Simon Willnauer 2014-01-23 14:49:16 +01:00
parent 416e328cea
commit a7a2d9f806
1 changed files with 28 additions and 22 deletions

View File

@ -412,9 +412,9 @@ public class RestTestSuiteRunner extends ParentRunner<RestTestCandidate> {
notifier.fireTestIgnored(rootDescription.getChildren().get(0));
return;
}
notifier.addListener(new RestReproduceInfoPrinter());
final RestReproduceInfoPrinter restReproduceInfoPrinter = new RestReproduceInfoPrinter();
notifier.addListener(restReproduceInfoPrinter);
try {
//the test suite gets run on a separate thread as the randomized context is per thread
//once the randomized context is disposed it's not possible to create it again on the same thread
final Thread thread = new Thread() {
@ -436,6 +436,12 @@ public class RestTestSuiteRunner extends ParentRunner<RestTestCandidate> {
notifier.fireTestFailure(new Failure(getDescription(),
new RuntimeException("Interrupted while waiting for the suite runner? Weird.", e)));
}
} finally {
// remove the listener once the suite is done otherwise it will print
// a bogus line if a subsequent test fails that is not a
// REST test. The RunNotifier is used across suites!
notifier.removeListener(restReproduceInfoPrinter);
}
}
@Override