Test Overview
This test demonstrates how to configure and run tests in parallel using JUnit 5. It verifies that two simple tests run concurrently without interfering with each other.
This test demonstrates how to configure and run tests in parallel using JUnit 5. It verifies that two simple tests run concurrently without interfering with each other.
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.parallel.Execution; import org.junit.jupiter.api.parallel.ExecutionMode; import static org.junit.jupiter.api.Assertions.assertTrue; @Execution(ExecutionMode.CONCURRENT) public class ParallelTest { @Test void testOne() throws InterruptedException { Thread.sleep(500); // Simulate work assertTrue(true); } @Test void testTwo() throws InterruptedException { Thread.sleep(500); // Simulate work assertTrue(true); } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | JUnit test runner starts and detects tests annotated with @Execution(CONCURRENT) | Test runner is ready to run tests in parallel | - | PASS |
| 2 | Test runner launches testOne and testTwo simultaneously on separate threads | Both tests are running concurrently | - | PASS |
| 3 | testOne executes Thread.sleep(500) then asserts true | testOne is running and simulating work | assertTrue(true) passes | PASS |
| 4 | testTwo executes Thread.sleep(500) then asserts true | testTwo is running and simulating work | assertTrue(true) passes | PASS |
| 5 | Both tests complete successfully without interference | Test runner collects results | Both tests passed | PASS |