Annotation 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
@Singleton
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
This annotation replaces the legacy maven-plugin-testing-harness functionality with a modern, annotation-based approach that integrates with JUnit Jupiter and Maven's new dependency injection framework.
- Since:
- 4.0.0
- See Also: