运行 在 Maven 分叉进程执行期间仅代码一次?

Running code only once during maven forked process execution?

场景: 我正在 运行使用 cucumberJVM 和 maven 分叉进程进行大量测试自动化。我只想 运行 一次,我该如何实现?显然,任何类型的全局 before all hook for cucumber(或类似的解决方法)最初都会在每个分叉进程上 运行 ,例如,在我所有的分叉进程执行测试之前考虑我想使用恢复数据库(简单的例子)带有 运行Once 布尔值的 @before 挂钩无论如何都会在每个分叉上 运行,我想我不太确定分叉何时发生以及如何拦截和在此之前的 运行 代码?

有人可以向我推荐一个很好的解决方案吗?

感谢您的宝贵时间。

Maven lifecycle might help here. Note the pre-integration-test phase. You could find plugins that do the kind of set up needed (database setup, starting Tomcat, etc), and bind executions of the plugin(s) to that phase. Then use the maven-failsafe-plugin 执行测试。有一个 post-integration-test 阶段允许拆除环境,还有一个单独的 verify 阶段用于检查结果。

Failsafe 插件文档提供了一个不错的概述。由于您计划 运行 并行测试,我建议您特别注意那些 sections/config 选项。