0
0
JUnittesting~5 mins

Custom extensions in JUnit - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a custom extension in JUnit?
A custom extension in JUnit is a user-defined class that adds extra behavior to tests, such as setup, teardown, or conditional test execution, by implementing JUnit's Extension API.
Click to reveal answer
beginner
Which JUnit interface do you implement to create a custom extension that runs code before and after each test?
You implement the BeforeEachCallback and AfterEachCallback interfaces to run code before and after each test method.
Click to reveal answer
beginner
How do you register a custom extension in a JUnit 5 test class?
You register a custom extension by annotating the test class with <code>@ExtendWith(YourExtension.class)</code>.
Click to reveal answer
intermediate
What is the purpose of the ExtensionContext parameter in JUnit custom extensions?
The ExtensionContext provides information about the current test, such as test method, test class, and a store for sharing data between callbacks.
Click to reveal answer
intermediate
Name two common use cases for creating custom JUnit extensions.
Common use cases include managing external resources (like databases or servers) and implementing conditional test execution based on environment or configuration.
Click to reveal answer
Which annotation is used to apply a custom extension to a JUnit 5 test class?
A@UseExtension
B@CustomExtension
C@ExtendWith
D@RegisterExtension
Which interface should you implement to run code before all tests in a test class?
ABeforeEachCallback
BTestWatcher
CTestExecutionListener
DBeforeAllCallback
What does the ExtensionContext NOT provide in a custom extension?
AAbility to modify test source code
BInformation about the current test method
CAccess to test class instance
DA store to share data between callbacks
How can you share data between different callbacks in a custom extension?
AUsing the ExtensionContext's store
BUsing static variables
CUsing global variables
DUsing environment variables
Which of the following is NOT a typical use case for custom JUnit extensions?
AConditional test execution
BChanging Java language syntax
CManaging external resources
DLogging test lifecycle events
Explain how to create and register a custom extension in JUnit 5.
Think about lifecycle interfaces and how JUnit knows to use your extension.
You got /3 concepts.
    Describe two practical scenarios where custom JUnit extensions improve testing.
    Consider what repetitive tasks or conditions you want to automate in tests.
    You got /2 concepts.