0
0
JUnittesting~20 mins

Parallel test configuration in JUnit - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Parallel Test Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
JUnit Parallel Execution Output
Given the following JUnit 5 test class configured to run tests in parallel, what will be the output order of the test methods?
JUnit
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;

@Execution(ExecutionMode.CONCURRENT)
public class ParallelTest {

    @Test
    void testA() throws InterruptedException {
        Thread.sleep(100);
        System.out.println("A");
    }

    @Test
    void testB() {
        System.out.println("B");
    }

    @Test
    void testC() throws InterruptedException {
        Thread.sleep(50);
        System.out.println("C");
    }
}
AB, C, A
BA, B, C
CC, B, A
DB, A, C
Attempts:
2 left
💡 Hint
Consider that tests run concurrently and sleep delays affect output timing.
assertion
intermediate
1:30remaining
Correct Assertion for Parallel Test Count
In a JUnit 5 test suite configured with junit.jupiter.execution.parallel.enabled = true and junit.jupiter.execution.parallel.config.fixed.parallelism = 3, which assertion correctly verifies that exactly 3 tests run in parallel?
AassertTrue(parallelismLevel >= 3);
BassertNotNull(parallelismLevel);
CassertFalse(parallelismLevel > 3);
DassertEquals(3, parallelismLevel);
Attempts:
2 left
💡 Hint
The fixed parallelism config sets the exact number of parallel threads.
🔧 Debug
advanced
2:00remaining
Debugging Parallel Test Failures
A JUnit 5 test suite runs tests in parallel but intermittently fails due to shared resource conflicts. Which change best fixes this issue?
ARemove <code>@Execution(ExecutionMode.CONCURRENT)</code> to run tests sequentially.
BIncrease <code>fixed.parallelism</code> to reduce test overlap.
CAdd <code>@ResourceLock("sharedResource")</code> to tests accessing the resource.
DUse <code>@TestInstance(Lifecycle.PER_CLASS)</code> to share state across tests.
Attempts:
2 left
💡 Hint
JUnit 5 provides annotations to control resource locking in parallel tests.
framework
advanced
1:30remaining
JUnit 5 Parallel Execution Configuration
Which configuration snippet correctly enables parallel test execution with a fixed thread pool of 4 threads in JUnit 5?
A
junit.jupiter.execution.parallel.enabled = false
junit.jupiter.execution.parallel.config.strategy = fixed
junit.jupiter.execution.parallel.config.fixed.parallelism = 4
B
junit.jupiter.execution.parallel.enabled = true
junit.jupiter.execution.parallel.config.strategy = fixed
junit.jupiter.execution.parallel.config.fixed.parallelism = 4
C
junit.jupiter.execution.parallel.enabled = true
junit.jupiter.execution.parallel.config.strategy = dynamic
junit.jupiter.execution.parallel.config.fixed.parallelism = 4
D
junit.jupiter.execution.parallel.enabled = true
junit.jupiter.execution.parallel.config.strategy = fixed
junit.jupiter.execution.parallel.config.fixed.parallelism = 2
Attempts:
2 left
💡 Hint
Parallel execution must be enabled and strategy set to fixed with desired parallelism.
🧠 Conceptual
expert
2:30remaining
Impact of Parallel Test Execution on Test Isolation
Which statement best describes the impact of enabling parallel test execution in JUnit 5 on test isolation?
AParallel execution can cause shared mutable state issues unless tests are designed for isolation.
BParallel execution guarantees complete test isolation by default.
CJUnit 5 disables static variables when parallel execution is enabled to ensure isolation.
DTests running in parallel always share the same instance, so isolation is not possible.
Attempts:
2 left
💡 Hint
Think about how shared data affects tests running at the same time.