Maven Surefire 和 Maven Failsafe 插件有什么区别?

What is the difference between the Maven Surefire and Maven Failsafe plugins?

Maven Surefire 和 Maven Failsafe 插件有什么区别?
我在网上搜索过,但没有得到答案。

来自https://maven.apache.org/surefire/maven-failsafe-plugin/,我会说 Surefire 和 Failsafe 之间的区别在于它们失败的方式:

If you use the Surefire Plugin for running tests, then when you have a test failure, the build will stop at the integration-test phase and your integration test environment will not have been torn down correctly.

The Failsafe Plugin is used during the integration-test and verify phases of the build lifecycle to execute the integration tests of an application. The Failsafe Plugin will not fail the build during the integration-test phase, thus enabling the post-integration-test phase to execute.

在我的国家/地区,搜索 "maven failsafe maven surefire" 以获取此常见问题解答时的第二个 google 结果:Difference between maven-failsafe-plugin and maven-surefire-plugin 其中指出:

maven-surefire-plugin is designed for running unit tests and if any of the tests fail then it will fail the build immediately.

maven-failsafe-plugin is designed for running integration tests, and decouples failing the build if there are test failures from actually running the tests."

简单来说,Failsafe 插件旨在 运行 集成测试 而 Surefire 运行 单元测试.

这在 Maven FAQ 中有进一步解释:

  • maven-surefire-plugin is designed for running unit tests and if any of the tests fail then it will fail the build immediately.

  • maven-failsafe-plugin is designed for running integration tests, and decouples failing the build if there are test failures from actually running the tests.

    The name "failsafe" was chosen both because it is a synonym of surefire and because it implies that when it fails, it does so in a safe way.

    The Failsafe Plugin has two goals:

另请参阅:

  • Benefits of Maven FailSafe Plugin 在 SO