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?
✗ Incorrect
The correct annotation to register a custom extension is
@ExtendWith. @RegisterExtension is used for field-level extensions.Which interface should you implement to run code before all tests in a test class?
✗ Incorrect
BeforeAllCallback runs code once before all tests. BeforeEachCallback runs before each test.What does the
ExtensionContext NOT provide in a custom extension?✗ Incorrect
ExtensionContext provides test info and data sharing but cannot modify test source code.How can you share data between different callbacks in a custom extension?
✗ Incorrect
The
ExtensionContext provides a Store to safely share data between callbacks.Which of the following is NOT a typical use case for custom JUnit extensions?
✗ Incorrect
Custom extensions cannot change Java syntax; they add behavior around tests.
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.