-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[misc] Hide output of succeeding tests (#512)
- Loading branch information
Showing
3 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package se.kth.spork; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.PrintStream; | ||
import org.junit.platform.engine.TestExecutionResult; | ||
import org.junit.platform.launcher.TestExecutionListener; | ||
import org.junit.platform.launcher.TestIdentifier; | ||
|
||
public class TestOutputHandler implements TestExecutionListener { | ||
private final PrintStream stdout = System.out; | ||
private final PrintStream stderr = System.err; | ||
|
||
private final ByteArrayOutputStream capturedStdout = new ByteArrayOutputStream(); | ||
private final ByteArrayOutputStream capturedStderr = new ByteArrayOutputStream(); | ||
|
||
@Override | ||
public void executionStarted(TestIdentifier testIdentifier) { | ||
System.setOut(new PrintStream(capturedStdout)); | ||
System.setErr(new PrintStream(capturedStderr)); | ||
} | ||
|
||
@Override | ||
public void executionFinished( | ||
TestIdentifier testIdentifier, TestExecutionResult testExecutionResult) { | ||
System.setOut(stdout); | ||
System.setErr(stderr); | ||
if (testExecutionResult.getStatus().equals(TestExecutionResult.Status.FAILED)) { | ||
System.out.printf( | ||
"### OUTPUT FROM %s (%s) ###", | ||
testIdentifier.getLegacyReportingName(), testIdentifier.getDisplayName()); | ||
System.out.println(capturedStdout.toString()); | ||
System.out.println(capturedStderr.toString()); | ||
} | ||
|
||
capturedStdout.reset(); | ||
capturedStderr.reset(); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
src/test/resources/META-INF/services/org.junit.platform.launcher.TestExecutionListener
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
se.kth.spork.TestOutputHandler |