在失败的测试中,Maven + Surefire返回码为0 [英] Maven + Surefire return code is 0 on failed tests

查看:69
本文介绍了在失败的测试中,Maven + Surefire返回码为0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,测试分为单元阶段和集成阶段.我让它运行buildbot,问题是即使在测试中失败,maven返回代码也为0,因此buildbot构建成功.

I have a project with tests split in unit and integration phases. I have it running buildbot and the problem is that even in tests are failing maven return code is 0 so buildbot build is succesful.

这是mvn集成测试的结果:

This is the result of mvn integration-test:

Results :

Tests in error: 
 Info about failed tests

Tests run: 5, Failures: 0, Errors: 5, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 minute 19 seconds
[INFO] Finished at: Tue Feb 12 09:43:53 UTC 2013
[INFO] Final Memory: 36M/97M
[INFO] ------------------------------------------------------------------------

$ echo $?
0

mvn安装的结果是相同的,但没有成功构建部分 结果:

Result for mvn install is the same without the build successful part Results :

Tests in error: 
  Info about failed tests

Tests run: 5, Failures: 0, Errors: 5, Skipped: 0

$ echo $?
0

Surefire配置如下:

Surefire configuration is like this:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.13</version>
  <configuration>
    <printSummary>true</printSummary>
    <excludedGroups>com.testlib.IntegrationTest</excludedGroups>
  </configuration>
  <executions>
    <execution>
    <id>unit-tests</id>
    <phase>test</phase>
    <goals>
      <goal>test</goal>
    </goals>
    <configuration>
          <excludedGroups>com.testlib.IntegrationTest</excludedGroups>
    </configuration>
    </execution>
    <execution>
    <id>integration-tests</id>
    <phase>integration-test</phase>
    <goals>
      <goal>test</goal>
    </goals>
    <configuration>
      <includes>
            <groups>com.testlib.IntegrationTest</groups>
      </includes>
        </configuration>
    </execution>
  </executions>
</plugin>

我已经阅读了有关maven返回代码的其他线程,但是从理论上讲,应该在我的maven版本(Apache Maven 2.2.1(rdebian-8))中修复相关的错误

I've reading other threads about maven return codes but in theory related bugs should be fixed in my maven version (Apache Maven 2.2.1 (rdebian-8))

有什么办法可以改变这种行为?

Is there any way to change this behaviour?

更新: 按照建议,我尝试使用surefire:

Update: As suggested I tried with surefire:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.13</version>
    <dependencies>
        <dependency>
        <groupId>org.apache.maven.surefire</groupId>
        <artifactId>surefire-junit47</artifactId>
        <version>2.13</version>
        </dependency>
    </dependencies>
    <configuration>
        <groups>com.testlib.IntegrationTest</groups>
    </configuration>
    <executions>
        <execution>
            <goals>
            <goal>integration-test</goal>
            <goal>verify</goal>
            </goals>
            <configuration>
                <includes>
                  <include>**/*.class</include>
                </includes>
            </configuration>
        </execution>
    </executions>

我需要surefire-junit来避免初始化错误.

I need the surefire-junit to avoid initialization errors.

推荐答案

我设法使其仅在使用surefire的情况下使用组和文件夹使用了两种不同的配置

I managed to have it working with two different configurations, using groups and using folders using just surefire

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.13</version>
    <configuration><excludedGroups>com.testlib.IntegrationTest</excludedGroups>
    </configuration>
    <executions>
        <execution>
            <id>integration-test</id>
            <phase>integration-test</phase>
            <goals>
                goal>test</goal>
            </goals>
            <configuration>
              <skip>false</skip>
                      <excludedGroups>com.biicode.testlib.UnitTest</excludedGroups>
                      <groups>com.testlib.IntegrationTest</groups>
            </configuration>
        </execution>
    </executions>

 <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        <excludes>
            <exclude>**/integration/*.java</exclude>
        </excludes>
    </configuration>
    <executions>
    <execution>
        <id>integration-test</id>
        <phase>integration-test</phase>
        <goals>
            <goal>test</goal>
        </goals>
        <configuration>
        <skip>false</skip>
        <excludes>
            <exclude>none</exclude>
        </excludes>
        <includes>
            <include>**/integration/*.java</include>
        </includes>
    </configuration>
  </execution>
  </executions>
</plugin>

这篇关于在失败的测试中,Maven + Surefire返回码为0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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