我希望Maven在遇到第一个错误时停止运行我的JUnit Spring测试。这个是可能的吗?
我的测试类如下所示,我将它们作为标准的Maven目标运行。
@ContextConfiguration(locations = {"classpath:/spring-config/store-persistence.xml","classpath:/spring-config/store-security.xml","classpath:/spring-config/store-service.xml", "classpath:/spring-config/store-servlet.xml" })
@RunWith(SpringJUnit4ClassRunner.class)
@Transactional
public class SkuLicenceServiceIntegrationTest
{
...如果Spring配置中有错误,那么每个测试都会尝试重新启动Spring上下文,每次需要20秒。这意味着我们在很长一段时间内都不会发现任何测试失败了,因为在得出构建失败的结论之前,它会尝试运行整个测试!
发布于 2011-10-17 18:51:24
这更多的是一句话,而不是一个答案,但是,也许你会发现它很有用。
我建议将您的集成测试分成一个单独的阶段,并使用Failsafe运行它们,而不是使用Surefire。这样,您就可以决定是只运行快速单元测试,还是需要长时间运行集成测试的全套测试:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<!-- Uncomment/comment this in order to fail the build if any integration test fail -->
<execution>
<id>verify</id>
<goals><goal>verify</goal></goals>
</execution>
</executions>
</plugin>
</plugins>您的问题的解决方法可能是将一个测试挑选到单独的执行中,并首先运行它;这样,执行将失败,并且后续的保证/故障安全执行将不会启动。参见how to configure the plugin to do it。
https://stackoverflow.com/questions/7792538
复制相似问题