A. Shared mutable state causes race conditions in concurrent tests
B. Missing @BeforeEach to reset counter before each test
C. No error; tests run correctly in concurrent mode
D. Incorrect use of @Execution; should be @Order
Solution
Step 1: Analyze shared state usage
The counter variable is shared and modified by both tests without synchronization.
Step 2: Understand concurrency impact
Running tests concurrently causes race conditions, leading to unpredictable counter values and test failures.
Final Answer:
Shared mutable state causes race conditions in concurrent tests -> Option A
Quick Check:
Concurrent tests + shared state = race condition [OK]
Hint: Avoid shared mutable state in concurrent tests [OK]
Common Mistakes:
Ignoring thread safety in concurrent tests
Assuming tests run sequentially by default
Confusing @Execution with @Order annotation
5. You have a test suite with some tests that modify shared data and others that do not. How can you use @Execution to optimize test speed while avoiding conflicts?
hard
A. Remove @Execution annotations and rely on default sequential execution
B. Annotate all tests with @Execution(ExecutionMode.CONCURRENT) to run all in parallel
C. Annotate tests that modify shared data with @Execution(ExecutionMode.SAME_THREAD) and others with CONCURRENT
D. Use @Execution(ExecutionMode.SAME_THREAD) on all tests to avoid conflicts
Solution
Step 1: Identify tests with shared data modification
Tests that modify shared data must run sequentially to avoid conflicts.
Step 2: Apply @Execution selectively
Use @Execution(ExecutionMode.SAME_THREAD) on tests with shared data, and CONCURRENT on others to speed up execution.
Final Answer:
Annotate tests that modify shared data with @Execution(ExecutionMode.SAME_THREAD) and others with CONCURRENT -> Option C
Quick Check:
Mix SAME_THREAD for shared data, CONCURRENT for others [OK]
Hint: Use SAME_THREAD for shared data tests, CONCURRENT for safe ones [OK]
Common Mistakes:
Running all tests concurrently ignoring shared data
Running all tests sequentially losing speed benefits
Not using @Execution selectively per test
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.