Stop Tests on first Failure with Maven/JUnit/Spring

那年仲夏 提交于 2019-12-08 02:49:49

问题


I'd like Maven to stop trying to run my JUnit Spring tests when it encounters the first error. Is this possible?

My test classes look like the following, and I run them just as a standard Maven target.

@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
{
...

If there's an error in the Spring config, then each test will try to restart the Spring context, which takes 20 seconds a go. This means we don't find out for ages that any tests have failed, as it'll try to run the whole lot before concluding that the build was a failure!


回答1:


This is more a remark, than an answer, but still, maybe you'll find it useful.

I'd recommend separating your integration tests into a separate phase, and running them with Failsafe, rather than Surefire. This way you can decide whether you need to run only fast unit tests, or the complete set with long-running integration tests:

    <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>

A workaround for your problem might be singling out a test into a separate execution and run it first; this way the execution would fail and subsequent surefire/failsafe executions will not be launched. See how to configure the plugin to do it.



来源:https://stackoverflow.com/questions/7792538/stop-tests-on-first-failure-with-maven-junit-spring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!