Annotation Type MojoTest


@Retention(RUNTIME) @ExtendWith(MojoExtension.class) @Target(TYPE) public @interface MojoTest
Annotation that enables Maven plugin (Mojo) testing support in JUnit tests. When applied to a test class, it automatically sets up the testing environment for Maven plugins, including dependency injection and parameter resolution.

This annotation works in conjunction with InjectMojo and MojoParameter to provide a comprehensive testing framework for Maven plugins. It automatically registers the MojoExtension which handles the plugin lifecycle and dependency injection.

Example usage:


@MojoTest
class MyMojoTest {
    @Inject
    private SomeComponent component;

    @Test
    @InjectMojo(goal = "my-goal")
    @MojoParameter(name = "parameter", value = "value")
    void testMojoExecution(MyMojo mojo) {
        // mojo is instantiated with the specified parameters
        // component is automatically injected
        mojo.execute();
        // verify execution results
    }

    @Provides
    SomeComponent provideMockedComponent() {
        return mock(SomeComponent.class);
    }
}

The annotation supports:

  • Automatic Mojo instantiation and configuration
  • Parameter injection via MojoParameter
  • Component injection via Inject
  • Mock component injection via Provides
  • Custom POM configuration via InjectMojo.pom()
  • Base directory configuration for test resources via Basedir
Since:
4.0.0
See Also:
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    boolean
    Indicates whether to use a real repository session for the test.
  • Element Details

    • realRepositorySession

      boolean realRepositorySession
      Indicates whether to use a real repository session for the test.
      When set to true, the test will utilize a real repository session, allowing for artifact resolution and repository interactions.
      Default:
      false