maven通过pom.xml文件集成多个testng.xml执行:
在maven中间通过pom.xml文件配置testng.xml,如果有多个testng.xml文件,可以把testng.xml文件配置在pom.xml,只需要运行pom.xml文件,就可以同时运行多个testng.xml中间的测试用例
例如:excludetestng.xml、testng.xml需要同时运行这两个文件中的测试用例,这两个配置文件可以同时配置到pom.xml,配置完成之后,只要运行pom.xml文件就可以同时执行这两个文件中间的测试用例
pom.xml需要增加一些配置,如下:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile> // 文件路径
<suiteXmlFile>excludetestng.xml</suiteXmlFile> //文件路径
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
如果有绝对路径就要写上,点击右侧Maven,展开TestNGDemo、Lifecycle,点击test,运行成功
TestNG自带的默认报告Use Default Report:
在测试过程中需要生成测试报告,TestNG自带的默认报告Use default reporters,运行testng.xml文件需要清楚的知道整个测试用例执行是否成功还是失败,通过测试报告反馈整个的执行结果
选中需要输出测试报告的testng.xml文件,如includetestng.xml,点击Run->Edit Configurations->Listeners->勾选Use default reporters->Apply->OK,再次运行includetestng.xml文件,会生成子目录test-output,展开能看到All Test includeTest,和includetestng.xml文件里suite标签里的name保持一致,在All Test includeTest下面能看到两个文件includeTest.html和includeTest.xml,和test标签里的name保持一致,如下图:

<suite name="All Test includeTest">:输出测试目录的名称,<test verbose="2" preserve-order="true" name="includeTest">:测试报告文件名,两种格式:html和xml格式,拷贝includeTest.html到桌面,右键打开方式,选择Google Chrome浏览器,打开报告如下图:

可以看到简易的测试报告
ReportNG插件美化自动化测试框架报告案例演示:
默认的测试报告没有达到我们的预期,需要通过一个插件ReportNG生成报告
第一步:需要pom.xml中间下载依赖包
<dependency>
<groupId>org.uncommons</groupId>
<artifactId>reportng</artifactId>
<version>1.1.4</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>4.2.0</version>
<scope>test</scope>
</dependency>
Maven-->clean、install把上面这两个依赖包下载到项目中间来了
第二步:需要把之前设置的默认报告,去勾选,includetestng.xml的默认勾选已去掉
第三步:testng.xml(includetestng.xml)在</test>下面新增:
<listeners>
<listener class-name="org.uncommons.reportng.HTMLReporter"></listener>
<listener class-name="org.uncommons.reportng.JUnitXMLReporter"></listener>
</listeners>
右键运行includetestng.xml,测试报告默认输出路径:test-output----->html路径,查看这个文件overview.html,右键open in
