zoukankan      html  css  js  c++  java
  • maven surefire插件与testng

    总结就是:参考文章:https://www.jianshu.com/p/2594dcbd3272

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

    Maven本身并不是一个单元测试框架,Java世界中主流的单元测试框架为JUnit和TestNG。Maven所做的只是在构建执行到特定生命周期阶段的时候,通过插件来执行JUnit或者TestNG的测试用例。这一插件就是maven-surefire-plugin,可以称之为测试运行器(Test Runner),他能很好的兼容JUnit 3、JUnit 4以及TestNG。

    我们知道,生命周期阶段需要绑定到某个插件的目标才能完成真正的工作,test阶段正是maven-surefire-plugin的test目标相绑定了,这是一个内置的绑定。

    1、maven-surefire-plugin插件默认会自动执行测试源码包(即test目录下)中遵循以下命名规则的java测试类。(有文章说如果测试method不是以test*开头,就不会执行到该测试方法。应该指的是没有做任何自定义configuration配置的默认情况下)

    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>属性来运行t指定的testng.xml执行测试套

    (将< suiteXmlFile>的value值设置为引用properties,则更灵活。执行命令时就可以指定想这些的testng.xml eg:mvn clean test -DsuiteXmlFile=src/test/resources/xml/a.xml)

    对应的pom.xml

    <properties>

            <suiteXmlFile>testng.xml</suiteXmlFile>

        </properties>

    <plugins>

                <plugin>

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

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

                    <version>2.19</version>

                    <configuration>

                        <encoding>UTF-8</encoding>

                        <suiteXmlFiles>

                            <suiteXmlFile>${suiteXmlFile}</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

  • 相关阅读:
    Vue 使用Scss,深度修改局部样式
    Sublime Text 插件:批量删除空白行
    Sublime Text 3前端开发常用优秀插件介绍
    常用的sublime text 3插件(很爽哦)
    20 个强大的 Sublime Text 插件
    Java多线程之synchronized详解
    进阶Java多线程
    初识Java多线程
    分布式锁实现的正确打开方式
    分布式session实现方式
  • 原文地址:https://www.cnblogs.com/happyliuyi/p/11009401.html
Copyright © 2011-2022 走看看