Maven JUnit4 plugin


Update: The Surefire plugin version 2.3 has reportedly been upgraded to support JUnit4. Please try adding the following to your pom.xml before continuing on with the information found on this page.


You can also read the full announcement maven-users mailing list.

Thanks to Chris Moesel for passing along the good news!


This Maven 2 plugin was developed to temporarily address a shortcoming in the standard Surefire plugin that prevents it from executing JUnit 4 test classes. This plugin is in no way intended to replace Surefire or even remain available after Surefire is upgraded. As such, no further work is expected to be done on this plugin.


The maven-junit4-plugin is executed during the test phase of the mvn lifecycle.

All JUnit 4 test classes that were built into the target/test-classes directory (the default test-compile output directory) will automatically be executed when the mvn test phase is run.


The paths for the project's classes and the test classes are hard-coded to the maven default values of target/classes and target/test-classes.

The surefire plugin's test phase is not disabled. There is therefore spurious Surefire output during the test phase.

No attempt is made to run JUnit 3 tests.

The unit tests run in the same JVM as maven itself. There is no forking model.

The unit tests for the plugin itself (i.e., if you were modifying the source code for maven-junit4-plugin) can not be run natively inside Eclipse itself. You either need to test the plugin via maven or set up Eclipse to execute mvn directly.


The maven-junit4-plugin should require no modifications to a project other than to the pom.xml file itself.

Add the following to the project's pom.xml:




The maven-junit4-plugin should download and install automatically when mvn test is run.

To run the plugin, execute:

 mvn test

Source Code

The pathological and curious alike can access the source code for the maven-junit4-plugin via the svn repository.

To check out a current copy of the maven-junit4-plugin source code, please run:

 svn co \

Further Reading