maven-failsafe-plugin错误和构建成功?

时间:2013-05-28 17:01:52

标签: maven maven-failsafe-plugin

我的问题与此问题非常相似:maven-failsafe-plugin Failures and BUILD SUCCESS?

如果测试失败,我设法将failafe插件设置为失败。

但是如果测试进入错误状态,failafe插件仍然不会破坏构建。

.................
-------------------------------------------------------
   T E S T S
-------------------------------------------------------
Running xxxxx.IntegrationTierFunctionalTestCase
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.054 sec <<< FAILURE!

Results :

Tests in error:
  testException(xxxxx.IntegrationTierFunctionalTestCas

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

[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is
[INFO] [failsafe:verify {execution: functional-test-1024}]
[INFO] Failsafe report directory: C:\projects\oec-integration-server\trunk\oec-integrati
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is
[INFO] [failsafe:integration-test {execution: functional-test-24}]
[INFO] Failsafe report directory: C:\projects\oec-integration-server\trunk\oec-integrati
.............
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 58 seconds
[INFO] Finished at: Tue May 28 17:48:13 BST 2013
[INFO] Final Memory: 114M/781M
[INFO] ------------------------------------------------------------------------

for simplicy IntegrationTierFunctionalTestCase仅包含此代码

import org.junit.Test;
import static org.junit.Assert.fail;
public class IntegrationTierFunctionalTestCase 
{

    @Test
    public void testException(){
        //fail();
        throw new RuntimeException("super error");
    }
}

如果我取消注释fail()整个构建失败,构建失败。 但是,如果我只是抛出异常,它会失败,如上所示。

oour插件配置如下所示

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.7</version>
    <configuration>
        <redirectTestOutputToFile>true</redirectTestOutputToFile>
        <systemPropertyVariables>
            <oec.env>TEST</oec.env>
            <mule.test.timeoutSecs>2400</mule.test.timeoutSecs>
        </systemPropertyVariables>
        <additionalClasspathElements>
            <additionalClasspathElement>${basedir}/src/main/resources/config</additionalClasspathElement>
            </additionalClasspathElement>
        </additionalClasspathElements>
    </configuration>
    <executions>
        <execution>
            <id>functional-test-1024</id>
            <phase>test</phase>
            <goals>
                <goal>integration-test</goal>
                <goal>verify</goal>
            </goals>
            <configuration>
                <includes>
                    <include>**/IntegrationTierFunctionalTestCase.java</include>
                </includes>
                <forkMode>once</forkMode>
                <argLine>-XX:MaxPermSize=256M -Xmx1024M</argLine>
            </configuration>
        </execution>
    </executions>
</plugin>

我错过了什么? 不,我不想将它包装在try-catch块中并手动失败测试。

4 个答案:

答案 0 :(得分:27)

你需要有两个执行块,因为maven-failsafe-plugin的验证目标是检查集成测试的结果。

  <executions>
    <execution>
        <id>functional-test-1024</id>
        <phase>test</phase>
        <goals>
            <goal>integration-test</goal>
        </goals>
        <configuration>
            <includes>
                <include>**/IntegrationTierFunctionalTestCase.java</include>
            </includes>
            <forkMode>once</forkMode>
            <argLine>-XX:MaxPermSize=256M -Xmx1024M</argLine>
        </configuration>
    </execution>
    <execution>
        <id>verify</id>
        <phase>verify</phase>
        <goals>
            <goal>verify</goal>
        </goals>
    </execution>
  </executions>

此外,您应该将maven-failsafe-plugin的版本更新为2.14.1而不是2.7。 更新:同时更新为2.17

答案 1 :(得分:11)

如果你正在运行这样的集成测试:

mvn test-compile failsafe:integration-test

然后你应该知道根据Angular JS documentation

  

在集成测试阶段,Failsafe插件不会使构建失败,从而使集成后测试阶段能够执行。

我能够让构建失败,如下所示:

mvn test-compile failsafe:integration-test failsafe:verify

这是我的故障安全配置供参考:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.19</version>
            <configuration>
                <includes>
                    <include>**/*IT.java</include>
                </includes>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>integration-test</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

答案 2 :(得分:1)

请验证maven属性&#34; maven.test.failure.ignore&#34;未设置为&#34; true&#34;在任何maven pom.xml文件中,因为它可能是在测试失败后停止构建的唯一原因。

答案 3 :(得分:0)

还有一个可能的原因。故障安全验证正在寻找测试类,并期望它们在$ {project.build.directory} / test-classes中 - 如果你有不同的设置它只会打印&#34;没有测试运行。&#34;如果构建成功,无论集成测试阶段的结果是什么,都会结束。

您必须在插件配置中设置 testClassesDirectory

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.18.1</version>

            <configuration>
                <systemPropertyVariables>
                    <environmentType>${environmentType}</environmentType>
                </systemPropertyVariables>
                <summaryFile>${project.build.directory}/failsafe-reports/failsafe-summary.xml</summaryFile>
                <testClassesDirectory>${project.build.directory}/classes</testClassesDirectory>
                <suiteXmlFiles>
                    <suiteXmlFile>${suiteXml}</suiteXmlFile>
                </suiteXmlFiles>
            </configuration>