The Maven Failsafe Plugin – Maven故障安全插件

最后修改: 2018年 4月 19日

中文/混合/英文(键盘快捷键:t)

1. Overview

1.概述

This to-the-point tutorial describes the failsafe plugin, one of the core plugins of the Maven build tool.

本教程开门见山地介绍了failsafe插件,这是Maven构建工具的核心插件之一。

For an overview of the other core plugins, refer to this article.

关于其他核心插件的概述,请参考这篇文章

2. Plugin Goals

2.插件目标

The failsafe plugin is used for integration tests of a project. It has two goals:

failsafe插件用于项目的集成测试。它有两个目标。

  • integration-test – run integration tests; this goal is bound to the integration-test phase by default
  • verify – verify that the integration tests passed; this goal is bound to the verify phase by default

3. Goal Execution

3.目标的执行

This plugin runs methods in test classes just like the surefire plugin. We can configure both plugins in similar ways. However, there’re some crucial differences between them.

这个插件在测试类中运行方法,就像surefire插件一样。我们可以用类似的方式配置这两个插件。然而,它们之间有一些关键的区别。

First, unlike surefire (see this article) which is included in the super pom.xml, the failsafe plugin with its goals must be explicitly specified in the pom.xml to be part of a build lifecycle:

首先,与包含在超级pom.xml中的surefire(见本文)不同,failsafe插件及其目标必须在pom.xml中明确说明,才能成为构建生命周期的一部分。

<plugin>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.21.0</version>
    <executions>
        <execution>
            <goals>
                <goal>integration-test</goal>
                <goal>verify</goal>
            </goals>
            <configuration>
                ...
            </configuration>
        </execution>
    </executions>
</plugin>

The newest version of this plugin is here.

该插件的最新版本是这里

Second, the failsafe plugin runs and verifies tests using different goals. A test failure in the integration-test phase doesn’t fail the build straight away, allowing the phase post-integration-test to execute, where clean-up operations are performed.

其次,failsafe插件使用不同的目标运行和验证测试。集成测试阶段的测试失败不会直接导致构建失败,允许后集成测试阶段执行,在该阶段进行清理操作。

Failed tests, if any, are only reported during the verify phase, after the integration test environment has been torn down properly.

失败的测试,如果有的话,只有在验证阶段,在集成测试环境被适当拆毁后才会报告。

4. Conclusion

4.结论

In this article, we introduced the failsafe plugin, comparing it with the surefire plugin, another popular plugin used for testing.

在这篇文章中,我们介绍了failsafe插件,将其与surefire插件进行比较,后者是另一个用于测试的流行插件。

The complete source code for this tutorial can be found over on GitHub.

本教程的完整源代码可以在GitHub上找到over

Next »

Quick Guide to the Maven Surefire Plugin

« Previous

Quick Guide to the Maven Install Plugin