0
0
JUnittesting~5 mins

@Execution annotation in JUnit - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
ASkips the tests
BRuns tests one after another in the same thread
CRuns tests only once
DRuns tests in parallel threads
Where can you apply the @Execution annotation?
AOn both test classes and methods
BOn individual test methods only
COn test classes only
DOn test suites only
Which execution mode should you use if your tests share mutable state?
ASAME_THREAD
BCONCURRENT
CPARALLEL
DASYNC
What is the default execution mode if @Execution is not specified?
ACONCURRENT
BSAME_THREAD
CASYNC
DPARALLEL
Which import is required to use @Execution in JUnit?
Aorg.junit.jupiter.api.parallel.Execution
Borg.junit.jupiter.api.Test
Corg.junit.jupiter.api.BeforeEach
Dorg.junit.jupiter.api.Assertions
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.