Файли
openidea/java/junit-runner
audichuang e6cb7df653 fix(run): count every test when JUnit runs them in parallel (#6377)
With JUnit's parallel concurrent mode, OpenIDEA's JUnit runner could report fewer tests than finished: the listener is called from several worker threads, Reporter's counters were plain ints incremented without a lock and PlatformRunner's start times a HashMap. The counting methods are synchronized now and the start times a ConcurrentHashMap. build.py --test runs a 4000-invocation parallel sample and expects the exact summary.

Closes #6334

Co-authored-by: audichuang <[email protected]>
2026-11-27 14:37:21 +08:00
..

JUnit runner

ai.openidea.junit.Runner runs the JUnit tests named by its arguments (com.acme.OrderTest, com.acme.OrderTest#method; a method selects every overload, so parameterized tests run too) and prints each test as the TeamCity service messages of src/features/run/gradleTests.gradle, which the Run window's JVM parser already reads. It exits with 1 when a test failed or none ran.

A test's stdout and stderr are reported with it (testStdOut, testStdErr), line by line as they are written; a class's own output (static initializers, @BeforeAll) with the class, and output outside any test, such as a thread the test started, is printed as is. Each line is printed once: JUnit's own output capture, which also copies everything to the original stream, stays off.

JUnit Platform tests run on the Platform launcher. JUnit 4 and JUnit 3 tests run on JUnit 4's own JUnitCore (Junit4Runner) when the classpath has no JUnit Platform, or one without the Vintage engine, so a JUnit 4 project needs nothing beyond its junit dependency.

OpenIDEA starts it for the gutter's JUnit tests of Maven modules (Settings › Maven › Run tests using: OpenIDEA) as java -ea -cp <test classpath>:<runner>[:<launcher>] ai.openidea.junit.Runner …. ide_sdk::java::junit_launcher picks junit-platform-launcher of the engine's version (none for JUnit 4 alone), and ide_build::surefire reads the module's Surefire configuration for the JVM (IDEA's MavenJUnitPatcher).

The jar is committed and embedded by ide-sdk (junit_runner_jar). Rebuild it after changing the source, and check it against JUnit 5 and JUnit 4 with:

python3 build.py --test
python3 build.py