如何配置Maven 2的surefire插件运行Junit 4.5? [英] How do I configure maven 2's surefire plugin to run Junit 4.5?

查看:92
本文介绍了如何配置Maven 2的surefire插件运行Junit 4.5?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Maven 2似乎没有考虑我的@Test和@Ignore批注.如何配置surefire插件以运行和使用注释?

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.

推荐答案

我首先将您的主POM配置为将surefire插件默认为最新版本.这是通过将条目添加到POM的插件管理部分来完成的.例如:

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>

现在将使用此版本的插件配置所有子POM,该插件支持JUnit 4.x注释.

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

如果这不起作用,那么我将确保您的JUnit测试文件与surefire插件期望的命名模式匹配,默认情况下为:**/Test*.java**/*Test.java**/*TestCase.java.我喜欢将我的JUnit类命名为*Tests.java,因此我对插件进行了如下调整:

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>

这篇关于如何配置Maven 2的surefire插件运行Junit 4.5?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆