0
0
JUnittesting~5 mins

Extension model overview in JUnit - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the JUnit Extension Model?
The JUnit Extension Model allows you to add custom behavior to tests, such as setup, teardown, or modifying test execution, without changing the test code itself.
Click to reveal answer
beginner
Name two common extension points in JUnit 5's Extension Model.
Two common extension points are BeforeEachCallback and AfterEachCallback, which run code before and after each test method respectively.
Click to reveal answer
beginner
How do you register an extension in JUnit 5?
You can register an extension by annotating the test class or method with <code>@ExtendWith(YourExtension.class)</code>.
Click to reveal answer
intermediate
What is the difference between BeforeAllCallback and BeforeEachCallback?
BeforeAllCallback runs once before all tests in a class, while BeforeEachCallback runs before each individual test method.
Click to reveal answer
intermediate
Why is the JUnit Extension Model useful for test code maintenance?
It helps keep test code clean by separating reusable setup or teardown logic into extensions, making tests easier to read and maintain.
Click to reveal answer
Which annotation is used to apply a JUnit 5 extension to a test class?
A@ExtendWith
B@TestExtension
C@UseExtension
D@EnableExtension
What does the AfterEachCallback interface allow you to do?
ARun code before all tests
BModify test method parameters
CRun code after each test method
DSkip tests conditionally
Which of these is NOT a valid JUnit 5 extension point?
ABeforeAllCallback
BAfterEachCallback
CBeforeTestExecutionCallback
DTestCaseListener
How often does BeforeAllCallback run in a test class?
ABefore each test method
BOnce before all test methods
CAfter each test method
DAfter all test methods
What is a key benefit of using the JUnit Extension Model?
AAdding reusable behavior without cluttering test code
BWriting tests without assertions
CAutomatically generating test data
DRunning tests in parallel
Explain how the JUnit Extension Model helps improve test code organization.
Think about how extensions reduce repeated code in tests.
You got /4 concepts.
    Describe the difference between BeforeEachCallback and BeforeAllCallback in JUnit extensions.
    Consider how often each callback runs during testing.
    You got /4 concepts.