Skip to content

Commit

Permalink
Avoid printing to STD_OUT in Test Kit demos during Gradle build
Browse files Browse the repository at this point in the history
Issue: #1621
  • Loading branch information
sbrannen committed Dec 17, 2018
1 parent c720ccc commit 5f40c6c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion documentation/src/docs/asciidoc/user-guide/testkit.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ include::{testDir}/example/testkit/EngineTestKitAllEventsDemo.java[tags=user_gui
<2> Select the <<testkit-engine-ExampleTestCase, `ExampleTestCase`>> test class.
<3> Execute the `TestPlan`.
<4> Filter by _all_ events.
<5> Print all events to the standard output stream (`STD_OUT`) for debugging purposes.
<5> Print all events to the supplied `writer` for debugging purposes. Debug information
can also be written to an `OutputStream` such as `System.out` or `System.err`.
<6> Assert _all_ events in exactly the order in which they were fired by the test engine.

The `debug()` invocation from the preceding example results in output similar to the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
import static org.junit.platform.testkit.engine.TestExecutionResultConditions.instanceOf;
import static org.junit.platform.testkit.engine.TestExecutionResultConditions.message;

import java.io.StringWriter;
import java.io.Writer;

import example.ExampleTestCase;

import org.junit.jupiter.api.Test;
Expand All @@ -36,11 +39,17 @@ class EngineTestKitAllEventsDemo {

@Test
void verifyAllJupiterEvents() {
Writer writer = // create a java.io.Writer for debug output
// end::user_guide[]
// For the demo, we are simply swallowing the debug output.
new StringWriter();
// tag::user_guide[]

EngineTestKit.engine("junit-jupiter") // <1>
.selectors(selectClass(ExampleTestCase.class)) // <2>
.execute() // <3>
.all() // <4>
.debug() // <5>
.debug(writer) // <5>
.assertEventsMatchExactly( // <6>
event(engine(), started()),
event(container(ExampleTestCase.class), started()),
Expand Down

0 comments on commit 5f40c6c

Please sign in to comment.