Recall & Review
beginner
What is the purpose of the
@Execution annotation in JUnit?The <code>@Execution</code> annotation controls whether tests in a test class or method run concurrently or sequentially in JUnit.Click to reveal answer
beginner
What are the two modes available with the
@Execution annotation?The two modes are CONCURRENT (tests run in parallel) and SAME_THREAD (tests run sequentially in the same thread).
Click to reveal answer
beginner
How do you apply <code>@Execution</code> to run all tests in a class concurrently?Add <code>@Execution(ExecutionMode.CONCURRENT)</code> above the test class declaration to run all its tests in parallel.Click to reveal answer
intermediate
Can
@Execution be used on individual test methods?No, <code>@Execution</code> is only applicable at the class level to control execution mode for all tests in that class.Click to reveal answer
intermediate
Why might you choose
ExecutionMode.SAME_THREAD over CONCURRENT?Use
SAME_THREAD when tests share state or resources that are not thread-safe, to avoid flaky or failing tests.Click to reveal answer
What does
@Execution(ExecutionMode.CONCURRENT) do in JUnit?✗ Incorrect
The CONCURRENT mode runs tests in parallel threads to speed up execution.
Where can you apply the
@Execution annotation?✗ Incorrect
@Execution is designed to be used on test classes to control execution mode for all tests inside.
Which execution mode should you use if your tests share mutable state?
✗ Incorrect
SAME_THREAD ensures tests run sequentially to avoid conflicts with shared mutable state.
What is the default execution mode if
@Execution is not specified?✗ Incorrect
JUnit runs tests sequentially by default, which corresponds to SAME_THREAD mode.
Which import is required to use
@Execution in JUnit?✗ Incorrect
The @Execution annotation is in the org.junit.jupiter.api.parallel package.
Explain how the
@Execution annotation affects test execution in JUnit.Think about running tests at the same time versus one by one.
You got /4 concepts.
Describe a scenario where you would prefer
ExecutionMode.SAME_THREAD over CONCURRENT.Consider tests that might interfere with each other if run at the same time.
You got /4 concepts.