java - 即使fail-on-end设置为true,当达到测试超时时,Maven也会确保构建失败

标签 java maven maven-surefire-plugin

在多模块 Maven 项目中,我想打印线程转储并在达到测试超时时使测试失败。因此,为了实现这一目标,我使用了 TimedoutTestsListener 的组合。肯定成功listener property .

我正在使用 Jenkins,因此 fail-on-end 设置为 true,以便所有不受影响的测试继续按上述方式运行 here .

那么,是否有可能仅在达到超时时立即构建失败,而在其他失败情况下最终失败?

  • JUnit - 4.12
  • Maven - 3.5
  • 万无一失 - 2.22.2
  • 贾夫 - 8

最佳答案

这已在 maven email group 中得到解答。

to fail the build immediately when timeout is reached

此功能已存在多年: http://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html#forkedProcessTimeoutInSeconds http://maven.apache.org/surefire/maven-failsafe-plugin/integration-test-mojo.html#forkedProcessTimeoutInSeconds

to fail the ... when someone presses abort button on the jenkins

这也存在多种替代方案(跨 版本)。查看详细页面 http://maven.apache.org/surefire/maven-failsafe-plugin/examples/shutdown.html

如果您的 Jenkins 将 SIGTERM 信号发送到 Maven 进程(相同 如 CTRL+C) 那么过程管道中的标准输入流就变成 关闭并且 EOFException 被 fork 的 JVM 捕获并关闭 叫做: http://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html#shutdown maven.apache.org/surefire/maven-failsafe-plugin/integration-test-mojo.html#shutdown 如果您想终止 JVM,可以重新配置默认行为。

如果您的 Jenkins 向 Maven 进程发送 SIGTERM,则启用 流程检查器,请参阅文档中的更多详细信息: http://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html#enableProcessChecker http://maven.apache.org/surefire/maven-failsafe-plugin/integration-test-mojo.html#enableProcessChecker

有帮助吗?

以下是常见问题解答: http://maven.apache.org/surefire/maven-failsafe-plugin/faq.html

如果您对此主题有任何疑问,请随时提出任何问题。

如果您使用的是 Surefire 3.0.0-M4,则可以在 target/surefire-reports 中找到线程转储。如上所述 here .

关于java - 即使fail-on-end设置为true,当达到测试超时时,Maven也会确保构建失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59243007/

相关文章:

java - FlyWayDB - 无法解析位置类路径

java - 来自 Java 的 MySQL 数据库查询失败

java - 如何在 IntelliJ IDEA 14 中为当前项目工作配置注释处理?

java - 具有不同系统属性值的多个 Maven 插件执行

java - maven-surefire-plugin 不适用于配置文件

java - try-catch around 回调

java - KeyPress 处理程序不适用于第一个字母

Maven Enforcer 插件 : Specify rules via command line

eclipse - 从eclipse导出maven项目并部署到tomcat上

java-8 - Java 8 : What is the equivalent of "UseSplitVerifier"?