Файли
openidea/java/junit-runner/tests/SampleTest.java
T
LU XIANGRUIтаwildcatDownstairs 5bcb37492f fix(run): print each line of a JUnit test's output once (#6333)
With Run tests using: OpenIDEA, every line a JUnit Platform test printed showed twice: the runner enabled JUnit's output capture, whose StreamInterceptor also writes each line to the original System.out, and then reported the captured text again as testStdOut.

The runner now captures System.out / System.err per thread itself, as Junit4Runner does: a thread's lines while it runs a test or a class's set-up go only into that test's or class's testStdOut / testStdErr, other output passes through, and JUnit's capture is turned off explicitly. The console now shows testStdErr as stderr, and "Show console when a message is printed to stderr" fires for it (also for Junit4Runner and the Gradle test init script).

Fixes #6332

Co-authored-by: wildcatDownstairs <[email protected]>
2026-11-27 14:14:49 +08:00

58 рядки
1.2 KiB
Java

package sample;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
class SampleTest {
static {
System.out.println("loaded");
}
@BeforeAll
static void setUp() {
System.out.println("class set-up");
}
@Test
void passes() throws InterruptedException {
System.out.println("hello [ünï]");
System.err.println("to stderr");
Thread other = new Thread(() -> System.out.println("from a thread"));
other.start();
other.join();
}
@Test
void fails() {
assertEquals(1, 2, "it's wrong");
}
@Test
@Disabled
void disabled() {}
@Test
void aborted() {
assumeTrue(false);
}
@ParameterizedTest
@ValueSource(ints = {1, 2})
void parameterized(int n) {
assertEquals(1, n);
}
@Nested
class Inner {
@Test
void nested() {}
}
}