Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I configure maven 2's surefire plugin to run Junit 4.5?

Maven 2 does not seem to consider my @Test and @Ignore annotations. How do I configure the surefire plugin to run and use the annotations?

This question is still not answered.

like image 432
gregm Avatar asked Oct 31 '25 01:10

gregm


1 Answers

I would first configure your master POM to default the surefire plugin to the latest version. This is done by adding an entry to the plugin management section of the POM. For example:

<pluginManagement>
   <plugins>
      <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-surefire-plugin</artifactId>
         <version>2.4.3</version>
      </plugin>
   </plugins>
</pluginManagement>

All child POMs will now be configured with this version of the plugin, which supports JUnit 4.x annotations.

If that doesn't work, then I would make sure your JUnit test files match the naming pattern(s) the surefire plugin expects, which by default are: **/Test*.java, **/*Test.java, and **/*TestCase.java. I like naming my JUnit classes like *Tests.java, so I tweak the plugin like so:

<pluginManagement>
   <plugins>
      <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-surefire-plugin</artifactId>
         <version>2.4.3</version>
         <configuration>
            <includes>
               <include>**/*Test*.java</include>
            </includes>
         </configuration>
      </plugin>
   </plugins>
</pluginManagement>
like image 71
SingleShot Avatar answered Nov 04 '25 04:11

SingleShot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!