2012-09-05 160 views
11

我想使用maven-failsafe-plugin来运行一些集成测试。如果任何测试失败,我希望Maven失败构建而不是BUILD BUILD SUCCESS。maven-failsafe-plugin失败并建立成功?

Tests run: 103, Failures: 1, Errors: 0, Skipped: 26 
[INFO] BUILD SUCCESS* 


如何我可以配置它,建造不是成功是什么?

我的故障安全插件配置为:

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-failsafe-plugin</artifactId> 
    <version>${failsafe.version}</version> 
    <configuration> 
     <systemProperties> 
      <CI_INTEGRATION_OVERRIDE_PATH>${basedir}/..</CI_INTEGRATION_OVERRIDE_PATH> 
     </systemProperties> 
     <includes> 
      <include>**/integration/**/*.java</include> 
     </includes> 
     <excludes> 
      <exclude>**/integration/**/*TestSuite.java</exclude> 
     </excludes> 
    </configuration> 
    <executions> 
     <execution> 
      <id>integration-test</id> 
      <goals> 
       <goal>integration-test</goal> 
       <goal>verify</goal> 
      </goals> 
     </execution> 
    </executions> 
</plugin> 
+0

您使用的是哪个版本的maven-failsafe-plugin?哪个Maven版本?你是怎么叫mvn来运行集成测试的? – khmarbaise

+2

关于“Maven - Users”,请参见[此邮件主题](http://maven.40175.n5.nabble.com/Failing-a-build-with-maven-failsafe-plugin-td3199308.html)。 –

+0

MAVEN CALL:mvn clean install -P罐故障安全:集成测试-e 2.12 MAVEN 3.16 – Fawi

回答

1

解决方案。

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <configuration> 
    <skip>true</skip> 
    </configuration> 
    <executions> 
    <execution> 
     <id>unit-test</id> 
     <phase>test</phase> 
     <goals> 
     <goal>test</goal> 
     </goals> 
     <configuration> 
     <skip>false</skip> 
     <excludes> 
      <exclude>**/*IntegrationTest.java</exclude> 
     </excludes> 
     </configuration> 
     </execution> 
     <execution> 
     <id>integration-test</id> 
     <phase>integration-test</phase> 
     <goals> 
      <goal>test</goal> 
     </goals> 
     <configuration> 
      <skip>false</skip> 
      <enableAssertions>false</enableAssertions> 
      <includes> 
      <include>**/*IntegrationTest.java</include> 
      </includes> 
      <systemPropertyVariables> 
      <integration>${integration}</integration> 
      </systemPropertyVariables> 
     </configuration> 
     </execution> 
    </executions> 
</plugin> 
+6

这个答案是用surefire插件取代故障安全插件。 – Andrew

1

既然你正在运行mvn clean installintegration-testverify阶段都应该执行。根据故障安全插件文档failsafe:integration-testfailsafe:verify的目标是绑定到这些阶段,所以我不认为需要额外致电failsafe:integration-test

这就是说,但我不确定我信任故障安全插件文档。我为answered a similar question今年早些时候的人。事实证明,他必须明确地将每个目标绑定到正确的阶段,然后按预期工作失败。可能值得一试。

+0

我找到了解决方案,我可以使用maven-surefire插件进行集成测试。 – Fawi

7

正如Andrew指出的那样,正确的解决方案是按照预期使用失效保护。集成测试目标是专门设计的,不会使构建失败。如果您想要构建失败,请致电mvn verifymvn failsafe:verify

+1

我同意你的回答。它的测试目标是设计不失败。 “我的目​​标是不同的,我想制作一本自以为是的软件,我更喜欢约定优于配置的概念。”正如Jason van Zyl在Maven文章的历史中引用的那样。遵守惯例总是很好的,而不是剽窃它来做非设计的东西。 – NewUser

+1

我经常发现,Maven作者的意图似乎与一个理智的人尝试使用它的方式直接相抵触。 – cbmanica