Recall & Review
beginner
What is the purpose of the
@ExtendWith annotation in JUnit?The
@ExtendWith annotation is used to register extensions in JUnit 5. Extensions add extra behavior to tests, like lifecycle callbacks or parameter injection.Click to reveal answer
intermediate
How do you apply multiple extensions using
@ExtendWith?You can apply multiple extensions by listing them inside
@ExtendWith like this: @ExtendWith({Extension1.class, Extension2.class}).Click to reveal answer
beginner
True or False:
@ExtendWith can only be used on test classes, not on individual test methods.False.
@ExtendWith can be used on both test classes and individual test methods to apply extensions at different scopes.Click to reveal answer
intermediate
What is a common use case for
@ExtendWith in JUnit testing?A common use case is to integrate third-party extensions like Mockito for mocking or to add custom behavior such as timing tests or managing resources.
Click to reveal answer
advanced
Explain how
@ExtendWith relates to JUnit 4's @RunWith annotation.@ExtendWith in JUnit 5 replaces @RunWith from JUnit 4. It provides a more flexible way to add extensions compared to the older runner mechanism.Click to reveal answer
What does the
@ExtendWith annotation do in JUnit 5?✗ Incorrect
@ExtendWith is used to register extensions that add extra behavior to tests, such as lifecycle callbacks or parameter injection.
How can you apply multiple extensions using
@ExtendWith?✗ Incorrect
You list multiple extensions inside curly braces like @ExtendWith({Ext1.class, Ext2.class}).
Can
@ExtendWith be used on individual test methods?✗ Incorrect
@ExtendWith can be applied at class or method level to control extension scope.
Which JUnit 4 annotation is replaced by
@ExtendWith in JUnit 5?✗ Incorrect
@ExtendWith replaces @RunWith to provide a more flexible extension mechanism.
Which of the following is NOT a typical use of
@ExtendWith?✗ Incorrect
@ExtendWith does not change method return types; it adds behavior or integrations.
Describe what the
@ExtendWith annotation does and give an example of when you might use it.Think about how you can add extra features to tests without changing test code.
You got /3 concepts.
Explain how
@ExtendWith differs from JUnit 4's @RunWith annotation.Consider flexibility and scope of application.
You got /4 concepts.