Maven Plugin Testing Harness
The Maven Plugin Testing Harness provides mechanisms to manage tests on Mojos, i.e. by pre-constructing the Plexus/Sisu components, providing stub objects for Maven functionality such as projects, and populating fields from an XML file that resembles the plugin configuration in the POM.
The Maven Plugin Testing Harness provides default stubs/mocks for most commonly used Maven objects, such as MavenProject, MavenSession, etc.
The best way to start is to read the cookbook How to use Maven Plugin Testing Harness.
Migration to 3.4.0
Since version 3.4.0, the Maven Plugin Testing Harness has been migrated to use JUnit 5 as the testing framework.
This change allows for more modern testing practices and improved integration with other tools.
JUnit 5 extension MojoExtension and annotation @MojoTest have similar functionalities
as in Maven 4
for easier migration of tests for Maven 4.
Project still supports JUnit 3/4 AbstractMojoTestCase and JUnit 4 MojoRule tests for backward compatibility
but new tests should be written using JUnit 5.
There are some migration receipts to help you migrate your existing tests.
Therefore, some project dependencies have been set as optional to avoid conflicts with existing JUnit 3/4 and JUnit 5 tests.
Your project should depend on the following artifacts, if needed:
org.codehaus.plexus:plexus-archiver- used byArtifactStubFactoryorg.apache.maven:maven-compat- used byMojoRule(not needed with Maven 3.9.12+)org.junit.jupiter:junit-jupiter-api- used for JUnit 5 testsjunit:junit- used for JUnit 3/4 tests
Examples
The following examples shows how to use the Testing Harness in more advanced use cases:



