使用TestNG-xslt

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

官方网址:http://code.google.com/p/testng-xslt/
用 户讨论区:http://groups.google.com/group/testng-xslt-users/topics

其 实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目录下
3. 然后再把/src/main/resources/testng-results.xsl放到你的测试目录里,或是随便一个什么目录下
4. 创建一个简单的build.xml, 如下:

<project name="myproject" basedir=".">
    <property name="lib.dir" value="lib"/>

    <path id="test.classpath">
         <!-- adding the saxon jar to your classpath -->
        <fileset dir="${lib.dir}" includes="*.jar"/>
    </path>

    <target name="transform">
        <xslt in="path/to/your/testng-results.xml"style="path/to/the/testng-results.xsl"
              out="/path/to/your/output/directory/index.html">
             <!-- you need to specify the directory here again -->
            <param name="testNgXslt.outputDir"expression="/path/to/your/output/directory/"/>
            <classpath refid="test.classpath"/>
        </xslt>
    </target>
</project>

最后执行ant transform就可以了,之后在output目录下就可以看到一个index.html文件,打开它就是测试报告了。

posted on 2011-04-20 13:50  张飞_  阅读(6838)  评论(1编辑  收藏  举报

导航