2017-05-25 135 views
2

如何跳过集成测试我想跳过集成测试,同时运行的Maven插件发布使用命令使用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。我不能在插件配置中配置所有的东西,因为一些选项在运行时需要环境变量。

回答

0

您可以在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> 
+0

我试图避免这种情况,因为大部分时间测试都会运行。只有当它被部署在CICD管道中。 Plus也不会跳过单元测试吗? – ddd

1

使用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 
+0

对不起,这只是错误的,因为maven-surefire-plugin不负责运行集成测试......并且这个命名模式默认没有被maven-surefire-plugin使用。这是来自maven-failsafe插件的命名模式... – khmarbaise