JUnit 5 supports running tests in parallel by configuring the platform to use multiple threads, which speeds up large test suites but requires tests to be written safely for concurrent execution.
Key Points: • Parallel execution is enabled via junit.jupiter.execution.parallel.enabled=true in a junit-platform.properties file. • Execution mode can be set per-class or per-method, and the strategy (fixed thread count or dynamic) is configurable. • Tests that share mutable static state, files, or database rows can produce flaky, order-dependent failures once run in parallel. • @Execution(ExecutionMode.SAME_THREAD) can force specific tests to avoid concurrency issues if they're not safe to parallelize. • Proper isolation - fresh test data per test, no shared mutable fields - is a prerequisite for safely enabling parallelism.
Example: Enabling parallel execution on a suite of 500 independent unit tests running on a multi-core CI runner can cut total test time significantly, but a test that writes to a shared temp file without isolation would start failing intermittently once parallelized.
Code Example:
junit.jupiter.execution.parallel.enabled=true
junit.jupiter.execution.parallel.mode.default=concurrentInterview Tip: A concise interview answer is:
"JUnit 5 can run tests in parallel by enabling it in junit-platform.properties and choosing a thread strategy, which speeds up large suites significantly. The catch is that tests must be properly isolated - no shared mutable state or files - or parallel execution surfaces flaky, order-dependent failures."