maven surefire插件与testng

时间:2019-06-12
本文章向大家介绍maven surefire插件与testng,主要包括maven surefire插件与testng使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

总结就是:

Maven surefire插件是一个执行maven项目测试代码的插件。

1、maven-surefire-plugin插件默认会自动执行测试源码包(即test目录下)中遵循以下命名规则的java测试类。

  1. **/Test*.java
  2. **/*Test.java
  3. **/*TestCase.java

对应的pom.xml

<build>

        <plugins>

            <plugin>

                <groupId>org.apache.maven.plugins</groupId>

                <artifactId>maven-surefire-plugin</artifactId>

                <version>2.19</version>

                <configuration>

                    <encoding>UTF-8</encoding>

                    <!--  <suiteXmlFiles>

                        <suiteXmlFile>TestNG.xml</suiteXmlFile>

                    </suiteXmlFiles>-->

                    <test>Order*.java</test><!-- test命令默认执行test目录下的文件 -->

                    <systemPropertyVariables>

                        <ddg.sys.name>htl_hse</ddg.sys.name>

                        <!-- <maven.surefire.debug>true</maven.surefire.debug> -->

                    </systemPropertyVariables>

                </configuration>

            </plugin>

</plugins>

</build>

2、也可以通过指定<suiteXmlFiles>属性来运行testng.xml执行测试套

对应的pom.xml

<plugins>

            <plugin>

                <groupId>org.apache.maven.plugins</groupId>

                <artifactId>maven-surefire-plugin</artifactId>

                <version>2.19</version>

                <configuration>

                    <encoding>UTF-8</encoding>

                    <suiteXmlFiles>

                        <suiteXmlFile>TestNG.xml</suiteXmlFile>

                    </suiteXmlFiles>

                </configuration>

            </plugin>

</plugins>

3、更多surefire plugin的使用方法可以通过maven-help-plugin插件查看当前测试插件绑定的生命周期
mvn help:describe -Dplugin=org.apache.maven.plugins:maven-surefire-plugin:2.7 -Ddetail

mvn surefire:help -Ddetail=true -Dgoal=test

原文地址:https://www.cnblogs.com/happyliuyi/p/11009401.html