Ant中批量调用TestNG的XML文件,并调用TestNgXlst生成漂亮的html测试报告

1 篇文章 0 订阅
1 篇文章 0 订阅

1、在Ant中设置如下:

    <target name="run_tests">    
        <testng classpathref="classpath.main"                
                failureproperty="test.failed">            
            <!--此目录下的所有TestNG的XML文件,使用*号表示此目录下所有 -->
            <xmlfileset dir="${suite.dir}">
               	<include name="*.xml"/>
            </xmlfileset>                        
        </testng>
    	
    	<!--TestNG执行完毕后,根据输出的testng-results.xml文件,按照testng-results.xsl的设定生成html格式的测试报告 -->
    	
		<echo taskname="OutputReport" message="start output report" />
		<xslt in="${test-output.dir}/testng-results.xml" style="${testNgXslt.dir}/config/testng-results.xsl" out="${testNgXslt.dir}/out/${CURTIME}/index.html">
			<param name="testNgXslt.outputDir" expression="${testNgXslt.dir}/out/${CURTIME}"/>
			<param name="testNgXslt.showRuntimeTotals" expression="true"/>
			<classpath refid="classpath.main"/>
		</xslt>  
    	
    </target>


在上述配置中,${testNgXslt.dir}/out/${CURTIME}表示测试报告输出的目录,${CURTIME}是根据测试执行时间标识,按照年月日时分秒格式。如下:

	<tstamp>   
		<format property="CURTIME" pattern="yyyyMMddHHmmss" locale="us"/>   
	</tstamp>   




  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
TestNG默认的测试报告是以XML格式输出的,如果想要生成HTML格式的测试报告,可以使用TestNG自带的`Reporter`类或第三方工具,如ExtentReports、Allure等。以下是使用Reporter类生成HTML格式测试报告的步骤: 1. 在TestNG测试添加`@Listeners(TestReportListener.class)`注解,引入自定义的监听器类。 2. 创建一个实现`ITestListener`接口的监听器类,重写`onTestSuccess`、`onTestFailure`、`onTestSkipped`等方法,在方法使用`Reporter.log`方法输出测试结果。 3. 运行测试后,会在项目目录下生成一个`test-output`文件夹,其包含了测试结果的XML文件和截图(如果有的话)。 4. 使用TestNG自带的`Reporter`类将XML文件转换为HTML格式的测试报告,代码如下: ```java import org.testng.Reporter; import org.testng.annotations.AfterSuite; import org.testng.annotations.BeforeSuite; public class TestReportListener implements ITestListener { @BeforeSuite public void beforeSuite() { Reporter.log("<html><head><title>Test Report</title></head><body>"); } @AfterSuite public void afterSuite() { Reporter.log("</body></html>"); Reporter.flush(); } @Override public void onTestSuccess(ITestResult result) { Reporter.log("<p style=\"color:green;\">Test Passed: " + result.getName() + "</p>"); } @Override public void onTestFailure(ITestResult result) { Reporter.log("<p style=\"color:red;\">Test Failed: " + result.getName() + "</p>"); } @Override public void onTestSkipped(ITestResult result) { Reporter.log("<p style=\"color:orange;\">Test Skipped: " + result.getName() + "</p>"); } // 将其他方法省略... } ``` 在`beforeSuite`方法输出HTML文件的头部,`afterSuite`方法输出HTML文件的尾部,并调用`Reporter.flush()`方法将结果写入HTML文件。在各个测试结果的处理方法,使用`Reporter.log`方法输出HTML格式的测试结果。 5. 运行测试后,在`test-output`文件生成一个`emailable-report.html`文件,即为HTML格式的测试报告
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值