简体   繁体   中英

How limit junit test run time in maven for all test?

There are sereral test some of them are too slow. Can maven be configured to skip/fail test when it is running say ore then 2000 milliseconds?

As pointed out by @KrishnanunniPV the forkedProcessTimeoutInSeconds can help you solve this issue. If you don't mind failed tests you would just need to add in your pom, in the build section:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.19.1</version>
    <configuration>
        <forkedProcessTimeoutInSeconds>2</forkedProcessTimeoutInSeconds>
    </configuration>
</plugin>

If you want your build to succeed even though the timeout has passed, you can just do:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.19.1</version>
    <configuration>
        <forkedProcessTimeoutInSeconds>2</forkedProcessTimeoutInSeconds>
        <testFailureIgnore>true</testFailureIgnore>
    </configuration>
</plugin>

我认为,最好将耗时过长的测试说成是集成测试(例如,将它们作为IT后缀),然后说使Maven在启用Maven集成测试配置文件时运行它们。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM