Recall & Review
beginner
What is the purpose of the
BeforeEachCallback interface in JUnit?It allows you to run custom code before each test method is executed, such as setting up test data or initializing resources.
Click to reveal answer
beginner
What does the
AfterEachCallback interface do in JUnit?It lets you run custom code after each test method finishes, useful for cleaning up resources or resetting states.
Click to reveal answer
intermediate
How do
BeforeEachCallback and AfterEachCallback relate to test lifecycle?They hook into the test lifecycle to run code right before and right after each test method, helping manage setup and cleanup automatically.
Click to reveal answer
beginner
Which method must be implemented when using
BeforeEachCallback?You must implement the
beforeEach(ExtensionContext context) method to define what happens before each test.Click to reveal answer
intermediate
What parameter is passed to the
afterEach method in AfterEachCallback?An
ExtensionContext object, which provides information about the current test and its environment.Click to reveal answer
What is the main use of
BeforeEachCallback in JUnit?✗ Incorrect
BeforeEachCallback runs code before each test method, helping prepare the test environment.
Which method must you override when implementing
AfterEachCallback?✗ Incorrect
The afterEach(ExtensionContext context) method is called after each test method finishes.
What does the
ExtensionContext parameter provide in these callbacks?✗ Incorrect
ExtensionContext gives info about the current test method and its context.
When is
AfterEachCallback code executed?✗ Incorrect
AfterEachCallback runs after each test method to clean up or reset states.
Can
BeforeEachCallback and AfterEachCallback be used together?✗ Incorrect
They complement each other to manage setup and teardown around each test method.
Explain how
BeforeEachCallback and AfterEachCallback help manage test setup and cleanup in JUnit.Think about what happens before and after each test method.
You got /4 concepts.
Describe the role of the
ExtensionContext parameter in the methods of BeforeEachCallback and AfterEachCallback.It helps the callback know about the test it is running around.
You got /3 concepts.