问题描述
我的问题与这一问题非常相似: maven-failsafe-plugin失败和成功建立?
my question is very similar to this one: maven-failsafe-plugin Failures and BUILD SUCCESS?
并且我设法将故障保护插件设置为在测试失败的情况下也会失败.
and I manage to set up failsafe plugin to fail if tests fail.
但是,如果测试进入错误状态,则故障保护插件仍不会破坏构建.
But if test goes into error state, failsafe plugin still does not break the build.
.................
-------------------------------------------------------
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] ------------------------------------------------------------------------
为简单起见IntegrationTierFunctionalTestCase仅包含此代码
for simplicy IntegrationTierFunctionalTestCase contains only this code
import org.junit.Test;
import static org.junit.Assert.fail;
public class IntegrationTierFunctionalTestCase
{
@Test
public void testException(){
//fail();
throw new RuntimeException("super error");
}
}
如果我取消注释fail(),则整个构建会正确失败,并且构建会失败.但是如果我只是抛出一个异常,则它将失败,如上所示.
if I uncomment fail() whole build fails correctly, with build failed.but if I just throw an exception, it fails as on shown above.
您的插件配置如下
<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块中并手动失败测试.
What am I missing?And no I do not want to wrap it in try-catch blocks and fail tests manually.
推荐答案
您需要两个执行块,因为maven-failsafe-plugin的验证目标旨在检查集成测试的结果.
You need having two executions blocks, cause the verify goal of the maven-failsafe-plugin is intended to check the results of the integration tests.
<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 .
Furthermore you should update the version of the maven-failsafe-plugin to 2.14.1 instead of 2.7.Update: In the meantime update to 2.17.
这篇关于maven-failsafe-plugin错误和构建成功?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!