Frequently Asked Questions

  1. What is a Mojo Testing Harness?
  2. What kind of unit tests are supported?
What is a Mojo Testing Harness?

A unit test attempts to verify a mojo as an isolated unit, by mocking out the rest of the Maven environment. A mojo unit test does not attempt to run your plugin in the context of a real Maven build. Unit tests are designed to be fast.

This testing library is NOT designed for integration or functional testing: maven-invoker-plugin is the way to go if you need it, which gives you a complete Maven environment at the cost of more resources and time consumption.

[top]


What kind of unit tests are supported?

JUnit 5 Extension - @MojoTest annotation
The preferred way to test Mojos is to use the JUnit 5 extension provided by the maven-plugin-testing-harness. You can annotate your test class with @MojoTest to have the extension set up the necessary Maven components for you. You can then inject your Mojo and any required Maven components directly into your test class. See javadocs for examples.
TestCase from JUnit - deprecated
You could use the JUnit framework to test your plugin in the same way you'd write any other JUnit test cases, i.e. by writing a test class which extends TestCase.
TestCase from Plexus - deprecated
Mojos are written to take specific advantage of the Plexus container. If you need Plexus container services, you could write your class which extends PlexusTestCase, instead of TestCase.
TestCase from Testing Harness - deprecated
If you need to inject Maven objects into your mojo, you could use the maven-plugin-testing-harness. The maven-plugin-testing-harness is explicitly intended to test the org.apache.maven.reporting.AbstractMavenReport#execute() implementation.

[top]