Frequently Asked Questions

  1. What is a Mojo Testing Harness?
  2. What kind of unit tests are supported?
  3. Is Mojo Testing Harness 2.x compatible with Maven 2.x?
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 consuptions.

[top]


What kind of unit tests are supported?

TestCase from JUnit
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
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
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]


Is Mojo Testing Harness 2.x compatible with Maven 2.x?

Mojo Testing Harness 2.0+ requires Maven 3.0. This does not necessary mean that your mojos will be incompatible with Maven 2.x, it only means that mojo unit tests use Maven 3.x libraries to mock Maven environment. Still, if you want to be absolutely sure your mojo is compatible with Maven 2.x, then you probably want to use Mojo Testing Harness 1.x.

[top]