(十一)Maven运行TestNG的testcase 两种方式:testng.xml和testngCase.java

摘要:
原文:https://blog.csdn.net/wwhrestarting/article/details/46596869?utm_source=copy1.通过maven-surefire-plugin来行maven项目中src/test/java文件夹下的testcase:默认情况下,testcase的命名规范必须是以下三种之一:"**/Test*.java"-includesallofi

原文:https://blog.csdn.net/wwhrestarting/article/details/46596869?utm_source=copy

1.通过maven-surefire-plugin来行maven项目中src/test/java文件夹下的testcase:

默认情况下,testcase的命名规范必须是以下三种之一:

"**/Test*.java" - includes all of its subdirectories and all Java filenames that start with "Test".
"**/*Test.java" - includes all of its subdirectories and all Java filenames that end with "Test".
"**/*TestCase.java" - includes all of its subdirectories and all Java filenames that end with "TestCase

Ps:以上命名规范在pom文件中自定义配置,关键代码如下:

<build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.18.1</version>
        <configuration>
          <includes>
            <include>Sample.java</include>
          </includes>
        </configuration>
      </plugin>
    </plugins>
  </build>
2.通过maven-surefire-plugin插件来运行工程目录主路径下的testng.xml(可配置)  
<plugins>
    [...]
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.18.1</version>
        <configuration>
          <suiteXmlFiles>
            <suiteXmlFile>testng.xml</suiteXmlFile>
          </suiteXmlFiles>
        </configuration>
      </plugin>
    [...]
</plugins>
PS: .xml文件必须在工程的主目录之下。
3.maven集成reportNG生成Html格式的测试报告:
在pom文件的dependencies中新增三个dependency:
velocity /guice /reportng
同时修改上述pom文件的maven-surefire-plugin部分代码:
<configuration>
    <suiteXmlFiles>
     <suiteXmlFile>testng.xml</suiteXmlFile>
    </suiteXmlFiles>
    
    <properties>
        <!-- Setting ReportNG listeners -->
    <property>
     <name>listener</name>
     <value>org.uncommons.reportng.HTMLReporter, org.uncommons.reportng.JUnitXMLReporter</value>
    </property>
            </properties>
</configuration>

免责声明:文章转载自《(十一)Maven运行TestNG的testcase 两种方式:testng.xml和testngCase.java》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇C# 通过进程名/进程Id 操作窗口/程序ARMCC和GCC编译ARM代码的软浮点和硬浮点问题【转】下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

testng生成报告ReportNG美化测试报告

testng生成报告ReportNG美化测试报告 testng生成报告ReportNG美化测试报告 ReportNG 是一个配合TestNG运行case后自动帮你在test-output文件内生成一个相对较为美观的测试报告!ReportNG 里面Log 是不支持中文的,我改过ReportNG.jar源码,具体方法看最下面,也可以找我直接要jar!话不多说直...

Maven测试篇

 Maven的生命周期:   讲解Maven测试篇之前将首先介绍一下Maven生命周期的相关概念,如果你熟知这部分概念可以略过此小节内容。   通常,我们在构建一个项目的时候,不外乎是对其进行清理、编译、测试和部署等操作。对于大多数项目,我们每次都要重复这些必要的过程,而Maven正是对这些必要的构建过程进行了抽象,它以项目的清理、初始化、编译、测试、...

一、Cucumber 环境配置

Cucumber是一个BDD(行为驱动开发)比较火的框架 地址:https://cucumber.io/docs/installation/java/ Maven地址,需要引入2个包: <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-java --> <...

TestNG入门——注解之Before/After

注解是java 5新增的功能,可使用于类,方法,变量,testNG包提供的注解功能请见下表 1、@BeforeSuite or @AfterSuite  被注解的方法,将在整个测试套件之前 or 之后执行。 2、@BeforeTest or @AfterTest 被注解的方法,将在测试套件内所有用例执行之前 or 之后执行。 3、@BeforeGroups...

11、testng.xml文件解析

我们可以从以下几种方式调用testng 用testng.xml ant 命令行 我们本次重点介绍testng.xml,testng.xml 文件来配置测试用例的执行 ,testng.xml文件可以很好的控制要执行的测试用例的粒度, 及各种运行策略。目前 testng.xml DTD(Document Type Definition; DTD 是一种 X...

java——testNG——工作复习——xml详解

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> <suite name="suitename"junit="false"verbose="3"parallel="false"thr...