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

依然范特西╮ 提交于 2019-12-05 03:16:39

问题


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.


回答1:


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>



回答2:


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?



来源:https://stackoverflow.com/questions/1336379/how-do-i-configure-maven-2s-surefire-plugin-to-run-junit-4-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!