Annotation Interface MavenDITest


@Retention(RUNTIME) @ExtendWith(MavenDIExtension.class) @Target(TYPE) public @interface MavenDITest
Annotation that enables Maven's dependency injection support in JUnit tests. When applied to a test class, it automatically sets up the DI container and performs injection into test instances.

This annotation is a convenient way to use MavenDIExtension without explicitly using @ExtendWith. It provides the same functionality as the legacy Plexus test support but uses Maven's new DI framework.

Example usage:

 
 @MavenDITest
 class MyComponentTest {
     @Inject
     private MyComponent component;

     @Test
     void testComponentBehavior() {
         // component is automatically injected
         assertNotNull(component);
         // perform test
     }
 }
 
 

The annotation supports:

  • Constructor injection
  • Field injection
  • Method injection
  • Automatic component discovery
  • Lifecycle management of injected components
Since:
4.0.0
See Also: