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.
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.
To use JUnit 4.x, you need to be using at least version 2.3 of the surefire-plugin (see SUREFIRE-31 on the Codehaus Jira for details). Note it is now generally considered good practice to version all your plugins (from Maven 2.1 onwards the common plugins are now versioned in the super POM).
If the tests are failing and you are using 2.3+ of the surefire plugin, can you update your question with the POM configuration you're using please?
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>