-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide a reliable way to report output from multithreaded and parallel tests #4323
Comments
As a build tool author, I can provide any custom |
I think that's an interesting idea! We have the same problem in our integration tests which trigger third-party tools like Gradle and Maven. For now, we're attaching their output as files using the new file attachment feature that will be released in 5.12 (see
That's true and partially due to now build tool consuming them in a meaningful way so far. You could make the case that's because they're not documented so we should definitely do that. There is now some special treatment in Lines 355 to 360 in ee52c64
I'll bring this up in the next team sync call. |
Thanks a lot @marcphilipp for your quick reply and your willingness to discuss this.
Indeed I noticed the I disabled the built-in output capture (and thus the I liked the |
TL;DR: I propose to:
TestReporter
, different frompublishEntry("stdout", "...")
. For example, providePrintStream
s likeTestReporter.out
andTestReporter.err
so the test authors can doTestReporter.out.println("...")
instead ofSystem.out.println()
.TestExecutionListener
to get streaming output coming from these new streams (as proposed in NotifyTestExecutionListener
of test stdout/stderr output continuously instead of all at the end #4317), or maybe some other reporting keys (different fromstdout
/stderr
) to get this output inreportingEntryPublished
.At the moment, JUnit doesn't recognize output from other threads than the original test thread, or at least it doesn't attribute them to the test it originates from. As we can see in the docs:
Properly dealing with output from
System.out.println()
on JUnit side would require something like Kotlin'sCoroutineContext
, and I'm not sure there is an equivalent in pure Java. So I get that it might be effectively impossible for JUnit to attribute regular output to a test (when using parallel execution).Nevertheless, test authors need a reliable way to print things from multithreaded tests while also ensuring it will be attributed to the proper test in reports and in listeners if run in parallel. While using
System.out
andSystem.err
is not possible, nothing prevents JUnit from providing aTestReporter.out
/TestReporter.err
mechanism, as mentioned in this comment: #780 (comment)Alternatives that don't seem appropriate:
TestReporter.publishEntry(String)
just publishes regular metadata under thevalue
key. Tools cannot really decide whether this should just be printed to the console, or added to the metadata of the test with other key-value pairs.TestReporter.publishEntry("stdout", "...")
seems like the perfect candidate at first glance, because it's exactly what is used by the stream capture mechanism to report the captured output. One problem with this is that it's unclear whether the same key can be used repeatedly for each line of output (a key-value store probably accepts only one value per key?). More importantly, theStreamInterceptingTestExecutionListener
reports the whole captured output in bulk at the end of the tests, which means that the output from background threads would come first, and then the output from the test thread will appear at the end, giving a very confusing ordering. See NotifyTestExecutionListener
of test stdout/stderr output continuously instead of all at the end #4317publish*
APIs seem mostly meant for reports / report entries (semantically), and don't feel appropriate to stream output to test listenersWith a special way to print output via the
TestReporter
, theTestExecutionListener
could have a new (pair of) callback(s) to receive stdout/stderr events that come either from the capturedSystem.out
/System.err
from the main test thread, or from these new print streams. See #4317.Alternatively, this could be achieved by piggy-backing on the existing
reportingEntryPublished
and using some new keys likestdout-stream
andstderr-stream
.The text was updated successfully, but these errors were encountered: