Junior — Middle
Is it permissible to apply the @ExtendWith annotation to any class when using testing?
sobes.tech AI
Answer from AI
The @ExtendWith annotation in JUnit 5 is used to connect extensions that add additional behavior to tests, such as lifecycle management, dependency injection, etc.
However, @ExtendWith can only be applied to test classes or test methods, not to arbitrary classes. That is, it should be used in the context of testing to extend the functionality of a test class or method.
Example of usage:
@ExtendWith(MockitoExtension.class)
public class MyTest {
// test methods
}
Applying @ExtendWith to a regular class that is not involved in testing does not make sense and will not work as expected.