unit-testing - 如何在 Maven 2 中的两个测试套件之间切换?

标签 unit-testing maven junit integration-testing maven-surefire-plugin

我们正在使用 maven-surefire-plugin运行我们的 Java 测试。测试分为两类:

  • 快速测试
  • 慢测试

  • 整个“快速”套件在几秒钟内运行,而慢速测试需要半小时。

    在开发过程中,我只想运行快速测试。当我提交时,我也希望能够运行慢速测试,所以运行慢速测试应该是一个选项,而快速测试应该是默认值。

    在 CI 服务器上,我想同时运行两者。

    当慢速测试包括快速测试时,这是可以的(甚至是首选)。

    对于这种情况,我应该如何设置 Maven、JUnit 和 Surefire?

    最佳答案

    您应该使用 junit 中的 Category:Junit category

    第一个解决方案

    配置 maven-surefire-plugin版本至少为 2.11

         <profile>
                        <id>normal</id>
                        <activation>
                                <activeByDefault>true</activeByDefault>
                        </activation>
                        <build>
                                <plugins>
                                        <plugin>
                                                <groupId>org.apache.maven.plugins</groupId>
                                                <artifactId>maven-surefire-plugin</artifactId>
                                                <configuration>
                                                        <excludedGroups>com.test.SlowTests</excludedGroups>
                                                </configuration>
                                        </plugin>
                                </plugins>
                        </build>
                </profile>
    

    第二种解决方案

    在配置部分,您可以添加带有文件的正则表达式以仅支持类(默认配置):
               <configuration>
                    <includes>
                        <include>**/*Test*.java</include>
                        <include>**/*Test.java</include>
                        <include>**/*TestCase.java</include>
                    </includes>
                </configuration>
    

    关于unit-testing - 如何在 Maven 2 中的两个测试套件之间切换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9533401/

    相关文章:

    python - 单元测试在python 2.6中崩溃(我正在使用Travis CI)

    ruby-on-rails - rails : "missing partial" when calling 'render' in RSpec test

    java - 使用静态内容运行 spring boot jar

    Maven 发布 :prepare : Cannot prepare the release because you have local modifications

    java - 有没有办法通过命令行将 JVM 参数传递给 Maven?

    java - 在测试方法实现中使用模拟对象

    javascript - [ngModelOptions] ="{standalone: true}"的 Angular 单元测试失败

    javascript - 使用 Jest 测试 Firebase 实时数据库

    java - 如何增加与数据库交互的类的测试覆盖率?

    java - Hibernate 在 emddable websphere 容器中找不到 java :comp/websphere/ExtendedJTATransaction