【问题标题】:How limit junit test run time in maven for all test?如何限制 Maven 中所有测试的 junit 测试运行时间?
【发布时间】:2017-03-22 06:41:01
【问题描述】:

有sereral test,有些太慢了。可以将 maven 配置为在运行 2000 毫秒时跳过/失败测试吗?

【问题讨论】:

标签: java maven junit maven-surefire-plugin


【解决方案1】:

正如@KrishnanunniPV 所指出的,forkedProcessTimeoutInSeconds 可以帮助您解决这个问题。如果您不介意测试失败,您只需要在您的 pom 中添加构建部分:

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

如果您希望构建成功,即使超时已过,您可以这样做:

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

【讨论】:

    【解决方案2】:

    我认为最好例如说需要太长时间的测试是集成测试(例如,将它们作为 IT 后缀),然后让 maven 在启用 maven 集成测试配置文件时运行它们。

    【讨论】:

    • 你说得很好,我只是添加一些例子来提高大家的理解
    猜你喜欢
    • 2013-08-23
    • 2021-12-16
    • 2019-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多