JUnit:选择性地不运行一些默认的测试用例 [英] JUnit: selectively not run a few test cases as default

查看:86
本文介绍了JUnit:选择性地不运行一些默认的测试用例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可能在构建时默认不运行某些JUnit测试用例?

Is it possible not to run some of the JUnit test cases by default at build time?

目标:

我们有两种测试用例:

  • 单元测试"
  • 集成测试"(测试到DB的完整路径)

在构建服务器上,我们不希望运行集成测试(数据库不可用,等等).但是,应该运行单元测试.目前,我们通过在CM中注释集成测试并在需要时由开发人员启用集成测试来实现这一目标.

On build server, we do not want integration tests to be run (DB not available, etc.). However, unit tests should be run. Currently we achieve this by keeping the integration tests commented out in CM and enabled by developers as needbed.

这是一个麻烦的安排.默认情况下,我们希望拥有的功能是告诉maven仅运行单元测试.我想可以做到这一点的一种方法是将集成测试保存在单独的软件包中,这不是默认构建的一部分.但是,这将使测试目标代码和测试用例在物理上保持分离,并且通常会随着时间的推移而失去同步.

This is a cumbersome arrangement. What we would like to have is as a default, tell maven to run only unit tests. One way this can be done I suppose is to keep integration tests in a separate package which is not part of default build. However, this will keep test target code and test cases physically separate and typically go out of sync over time.

有什么好的解决方法吗?

Any good solutions?

推荐答案

您可以在pom中使用其他配置文件.默认情况下,您不包括集成测试.

You could use different profiles in pom. In default you exclude integrationtests.

<plugin>
     <artifactId>maven-surefire-plugin</artifactId>
     <groupId>org.apache.maven.plugins</groupId>
     <version>2.9</version>
     <configuration>
         <skip>false</skip>
         <useFile>false</useFile>
         <argLine>-Xms1024m -Xmx1024m -XX:MaxPermSize=512m</argLine>
         <excludes>
             <exclude>**/*IntegrationTest.java</exclude>
         </excludes>
     </configuration>
</plugin>

<profiles>
    <profile>
        <id>integration-test-builder</id>
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <groupId>org.apache.maven.plugins</groupId>
                    <version>2.9</version>
                    <configuration>
                        <skip>false</skip>
                        <useFile>false</useFile>
                        <argLine>-Xms1024m -Xmx1024m -XX:MaxPermSize=512m</argLine>
                        <excludes>
                            <exclude>none</exclude>
                        </excludes>
                        <includes>
                            <include>**/*IntegrationTest.java</include>
                        </includes>
                    </configuration>
                    <executions>
                        <execution>
                            <id>integration-tests</id>
                            <phase>integration-test</phase>
                            <goals>
                                <goal>test</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>    
</profiles>

要简单地运行Integrationstest,请执行以下操作:mvn clean集成测试-P集成测试生成器

To run integrationstest you simple do: mvn clean integration-test -P integration-test-builder

这篇关于JUnit:选择性地不运行一些默认的测试用例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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