使用TestNG-xslt美化测试报告

本文介绍了一种使用testNG-xslt工具美化TestNG自动生成的测试报告的方法。通过下载并配置testNG-xslt,可以将原始的testng-results.xml文件转换为更易阅读的HTML格式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

用后,自动会生成html的测试报告,不过相信大家都有感觉,自动生成的测试报告太难看了,所以我们又用了ReportNG来美化它。在 这里给大家再介绍一下比reportNG还要稍稍美观一点的reporting tool: testNG-xslt.

其实testNG-xslt就是把testNG自动生成的测试报告testng-results.xml进行了一个转换,把它的html输出报告变得更漂亮 而已。因此用法也很简单:

1. 在官方网站上下载testNG-xslt ,http://testng-xslt.googlecode.com/files/testng-xslt-1.1.zip

2. 解压后把saxon-8.7.jar放到project的lib目录下(在bulid路径里也把这个lib加上)

3. 然后再把/src/main/resources/testng-results.xsl放到你的 test-output 目录下

4. 在测试项目的根目录下创建一个简单的build.xml, 如下:

<?xml version="1.0" encoding="UTF-8"?>

<project name= "testTng" basedir= "." default="transform">

<property name= "lib.dir" value= "lib" />

<path id= ".classpath" >

<!-- adding the saxon jar to your classpath -->

<fileset dir= "${lib.dir}" includes= "*.jar" />

</path>

<target name= "transform" >

<xslt in= "G:/eclipse3.7/workspace/testTng/test-output/testng-results.xml" style= "G:/eclipse3.7/workspace/testTng/test-output/testng-results.xsl"

out= "G:\eclipse3.7\workspace\testTng\test-output\index1.html " >

<!-- you need to specify the directory here again -->

<param name= "testNgXslt.outputDir" expression= "G:\eclipse3.7\workspace\testTng\test-output" />

<classpath refid= "test.classpath" />

</xslt>

</target>

</project>

5.最后用 ant 运行这个 xml 就会在test-output 目录下生成 index1.html,打开它就是测试报告了。

转换前的测试报告:

转换后的测试报告(是不是美观很多呢):

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值