【问题标题】:how to skip integration tests with maven release plugin如何使用 Maven 发布插件跳过集成测试
【发布时间】:2017-05-25 14:57:58
【问题描述】:

我想在使用命令运行 maven 发布插件时跳过集成测试

mvn -B -DskipITs release:prepare release:perform

它似乎不以这种方式工作。相同的选项-DskipITs 适用于mvn install/deploy。我不想使用-Dmaven.test.skip=true,因为只需要忽略集成测试,而不是单元测试。实现这一目标的最佳方法是什么?

编辑-Darguments=-DskipITs 适用于 release:prepare,但令人惊讶的是它适用于 release:perform。试过-Darguments=-Dmaven.test.skip=true,也不行。

尝试在 pom 中为发布插件添加<arguments>skipITs</arguments>,但它会忽略命令行中提供的所有其他-Darguments。我无法在插件配置中配置所有内容,因为某些选项会即时使用环境变量。

【问题讨论】:

    标签: java maven integration-testing maven-release-plugin


    【解决方案1】:

    根据how to make maven release plugin skip tests,您似乎需要-DskipITs-Darguments=-DskipITs。一种是跳过编译 IT,另一种是跳过正在运行的 IT。

    【讨论】:

    • 似乎无法编辑帖子:有一个错字,-DskitITs 应该是 -DskipITs
    【解决方案2】:

    使用 Maven Profiles

    将以下内容添加到您的 pom 中:

    <profiles>
        <profile>
            <id>ItsReleaseTime</id>
            <build>
            <plugins>
            <build> 
                <plugins> 
                   <plugin>          
                       <groupId>org.apache.maven.plugins</groupId> 
                       <artifactId>maven-surefire-plugin</artifactId>
                       <version>2.20</version>    
                       <configuration>
                            <excludes>    
                                  <exclude>**/*IT.java</exclude> 
                            </excludes> 
                       </configuration> 
                   </plugin>
                </plugins>       
            </build>
        </profile>
    </profiles>
    

    并调用命令:

    mvn -B -P ItsReleaseTime release:prepare release:perform
    

    【讨论】:

    • 抱歉,这完全是错误的,因为 maven-surefire-plugin 不负责运行集成测试......并且默认情况下,maven-surefire-plugin 不使用此命名模式。这是来自 maven-failsafe-plugin 的命名模式...
    【解决方案3】:

    您可以在pm.xml 文件中添加一些设置。

       <plugin>
        <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.12.4</version>
          <configuration>
             <skipTests>true</skipTests>
          </configuration>
       </plugin>
    

    【讨论】:

    • 我试图避免这种情况,因为大多数时候测试都会运行。仅当它被部署在 CICD 管道中时。另外,这不会跳过单元测试吗?
    • 问题是关于跳过集成测试;并非所有测试
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多