-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Open
Labels
Description
As documented, JUnit loses stdout (and therefore log lines) when execution crosses into a new thread inside a test. This can be confusing because the printed text just disappears, which is unintuitive.
The stated rationale is that "it would be impossible to attribute [the output] to a specific test or container". Whilst there's no general way to do it:
- It would be better to just emit to stdout directly if it can't be properly captured rather than losing the printing.
- Using
InheritableThreadLocal
will handle the common case where code starts a thread as part of its work and then shuts the thread down, as that way the underlyingRewindableByteArrayOutputStream
will be propagated.
In theory (!) it's a simple enough change. As well as changing the TLS slot type, the RewindableByteArrayOutputStream
needs to be made thread safe.
elshad-faire, travisMiehm and joffrey-bion