0
0
JUnittesting~5 mins

@ExtendWith annotation in JUnit - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AMarks a method as a test case
BRegisters extensions to add behavior to tests
CDefines the order of test execution
DSkips a test method
How can you apply multiple extensions using @ExtendWith?
ABy listing them in an array inside <code>@ExtendWith</code>
BBy using multiple <code>@ExtendWith</code> annotations on the same class
CBy calling extensions inside the test method
DBy using <code>@RunWith</code> instead
Can @ExtendWith be used on individual test methods?
AOnly on interfaces
BNo, only on classes
CYes, it can be used on both classes and methods
DOnly on constructors
Which JUnit 4 annotation is replaced by @ExtendWith in JUnit 5?
A<code>@RunWith</code>
B<code>@Test</code>
C<code>@Before</code>
D<code>@Ignore</code>
Which of the following is NOT a typical use of @ExtendWith?
AIntegrating third-party libraries like Mockito
BAdding custom test lifecycle behavior
CInjecting parameters into test methods
DChanging the test method's return type
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.