A developer complains that test `println`/log output 'disappears' and isn't shown on the console. Where does Gradle put that output by default, and how do the reports relate to it?
answer
- stdout/stderr captured, not dropped
- HTML class page has output sections
- JUnit-XML <system-out>/<system-err>
- outputPerTestCase for per-test XML
- testLogging.showStandardStreams for console
basics
~20 sBy default Gradle captures each test's stdout/stderr and folds it into the test reports (HTML page per class and, optionally, the JUnit-XML) instead of streaming it to the console. Open the HTML report to see it, or enable testLogging.showStandardStreams.
solid answer
~40 sGradle doesn't drop test output — it **captures** stdout/stderr per test and routes it into the reports rather than the live console. In the **HTML report**, each test class page has a 'Standard output'/'Standard error' section. For the **JUnit-XML**, setting `reports.junitXml.outputPerTestCase = true` captures output at the per-test-case level into the XML (otherwise it's aggregated per class). If you want it on the console during the run, use the task's `testLogging` block: ```kotlin tasks.test { testLogging { showStandardStreams = true events("passed", "skipped", "failed") } } ``` So 'disappeared' output is almost always sitting in `build/reports/tests/test/index.html` under the relevant class. `testLogging` controls console streaming; `reports` controls what lands in the files.
code
kotlin · 9 linestasks.test {
// put captured output into the console live
testLogging {
showStandardStreams = true
events("passed", "skipped", "failed")
}
// attribute captured output to each test case in the XML
reports.junitXml.outputPerTestCase = true
}go deeper
Know the output is in the HTML report, not lost.
Distinguish reports vs testLogging and know outputPerTestCase / showStandardStreams.
Explain capture-by-default rationale incl. parallel-fork interleaving and CI XML drill-down.
Set sane org defaults (quiet console, rich XML) balancing CI log volume against debuggability.
## Output is captured, not lost When tests run, anything they write to `System.out`/`System.err` (including logging that ultimately writes to stdout) is **captured** by Gradle's test executor. By default this captured text is **not** echoed to the build console — it's stored so it can appear in the reports. That's why developers think it 'disappeared'. ## Where to find it - **HTML report** (`build/reports/tests/test/index.html`): drill into the failing/passing class; each class page shows captured *Standard output* and *Standard error* sections. This is the usual place to read it. - **JUnit-XML** (`build/test-results/test/TEST-*.xml`): output is embedded in `<system-out>`/`<system-err>` elements. By default it's aggregated per class; set `reports.junitXml.outputPerTestCase = true` to attribute output to individual `<testcase>` entries (useful for CI drill-down, at the cost of larger XML). ## Streaming to the console instead If you want output live during the run, that's a `testLogging` concern (separate from `reports`): ```kotlin tasks.test { testLogging { showStandardStreams = true // echo captured stdout/stderr exceptionFormat = TestExceptionFormat.FULL events("passed", "skipped", "failed") } } ``` ## The mental split - `reports { ... }` decides **what gets written to the HTML/XML files**. - `testLogging { ... }` decides **what gets printed to the console** as the build runs. They are independent: you can have rich files and a quiet console, or a chatty console and minimal files. Both ultimately read from the same captured streams. ## Parallelism caveat With parallel forks (`maxParallelForks > 1`), interleaved console streaming is messy, which is another reason Gradle defaults to capturing into per-test report sections rather than the shared console.
- What's the difference between `testLogging` and `reports` regarding output?`testLogging` controls what's streamed to the build console as tests run; `reports` controls what captured output lands in the HTML/JUnit-XML files. Independent knobs over the same captured streams.
- How do you get per-test-case stdout into the JUnit-XML?Set `reports.junitXml.outputPerTestCase = true`, which records output under individual `<testcase>` `<system-out>`/`<system-err>` instead of aggregating per class.
saying these in an interview costs you the question
- Saying Gradle discards test output by default (it captures it into reports)
- Confusing `testLogging` (console) with `reports` (files)
- Assuming output always streams live regardless of config