Maven-Surefire插件有什么用

问题描述 投票:0回答:5

Maven Surefire 插件有什么用? 我找不到合适的例子。

maven maven-surefire-plugin
5个回答
34
投票

最好从 https://maven.apache.org/surefire/maven-surefire-plugin/

开始

在短链接中说:

Surefire 插件在构建的测试阶段使用 执行应用程序的单元测试的生命周期。它生成 两种不同文件格式的报告 纯文本文件 (.txt) XML 文件 (.xml)


16
投票

Maven Sure Fire 插件用于遵循 testng.xml 文件中的测试顺序。如果我们不包含 Mavwen Surefire 插件,那么它将执行 src/test/java 下前缀或后缀为“test”的所有测试用例,并且这些测试将在没有任何顺序的情况下执行。


12
投票

在这里你可以找到关于surefire是什么以及它在maven生命周期中扮演什么角色的最佳描述。

它由 Maven 生命周期在适当的阶段隐式调用,因此它是一个“special”插件。我们不需要在 pom.xml 中定义它,当 maven 需要它时,它会被下载并执行。

它内部只有一个目标,毫无疑问就是“测试”,并且是由 apache 人员定义的,

测试:允许我们运行应用程序的单元测试

不过,我们可以在 pom.xml 中表示它来运行 src/test/java 文件夹的单元测试。

<build>
    <plugins>
        <plugin>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.4</version>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19</version>
        </plugin>
    </plugins>
</build>

6
投票

maven-surefire-plugin,每当执行测试目标时默认使用[例如“mvn test”/“mvn install”]。 您可以在 pom.xml 中配置此插件以提供一些配置信息,例如测试工件的位置 [testng.xml] 或直接包含条件的选项(定义组、排除组、线程数、parallelismskip)在 pom.xml 中使用插件配置。 因此,您可以选择将该信息放在哪里(在 pom.xml 中或在套件 testng.xml 中)

早些时候,当 Junit 滞后于并行执行时,这是一个很大的帮助


0
投票

根据 Apache,surefire 插件的用途是

Surefire 插件在构建生命周期的测试阶段使用来执行应用程序的单元测试。它生成两种不同文件格式的报告:

Apache Surefire 插件

所有带有 @test 注释的单元测试都将被执行。但您也可以使用该插件添加或排除这样的测试:

<plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.22.2</version>
    <configuration>
        <excludes>
            <exclude>DataTest.java</exclude>
        </excludes>
        <includes>
            <include>DataCheck.java</include>
        </includes>
    </configuration>
</plugin>
© www.soinside.com 2019 - 2024. All rights reserved.