使用reportNG替换testNG的默认报告

reportNG替换testNG

reportng的官网介绍:http://reportng.uncommons.org/

1.下载reportNG的jar包:http://pan.baidu.com/s/1hq5znLU

2.reprotNG的源码:https://github.com/dwdyer/reportng

3.在项目中导入reportNG的jar包

Maven 库配置地址

<dependency>
    <groupId>org.uncommons</groupId>
    <artifactId>reportng</artifactId>
    <version>1.1.4</version>
    <scope>test</scope>
</dependency>

4.更改eclipse设置

5.设置完成后,运行项目,在项目test-output/html/index.html即可查看report


监听名:org.uncommons.reportng.HTMLReporter

           

6、配置testng的xml配置文件

            

       贴出来,便于拷贝:  

            <listeners>
                     <listener class-name="org.uncommons.reportng.HTMLReporter" />
                     <listener class-name="org.uncommons.reportng.JUnitXMLReporter" />
            </listeners>

           


7.设置reportng的编码

更改源文件的AbstractReporter.java,并替换相应jar包的class

    protected void generateFile(File file,
                                String templateName,
                                VelocityContext context) throws Exception
    {
        //Writer writer = new BufferedWriter(new FileWriter(file));
        //encoding to utf-8
        OutputStream out=new FileOutputStream(file);
        Writer writer=new BufferedWriter(new OutputStreamWriter(out,"utf-8"));
        try
        {
            Velocity.mergeTemplate(classpathPrefix + templateName,
                                   ENCODING,
                                   context,
                                   writer);
            writer.flush();
        }
        finally
        {
            writer.close();
        }
    }

 

8.更改报告的方法排列顺序,按照方法的执行先后顺序来进行排序的

更改TestResultComparator.java,并替换相应jar包的class

     public int compare(ITestResult result1, ITestResult result2)
     {
         //return result1.getName().compareTo(result2.getName());
         int longresult2 = 0;
         if(result1.getStartMillis()<result2.getStartMillis()) {
             longresult2 = -1;
         }else {
             longresult2 = 1;
         }
         return longresult2;
     }

 9.更改报告输出样式

在reportng-1.1.4.jar的reportng.properties文件中增加

oneclass.description=Description
oneclass.duration=Duration
oneclass.testdata=Data being used
oneclass.testresult=Test result
oneclass.screenshot=Screen shot
oneclass.additionalinfo=Additional Info

在reportng-1.1.4.jar的results.html.vm文件中更改

<tr>
<td colspan="1" class="group">$testClass.name</td>
<td colspan="1" class="group">$messages.getString("oneclass.duration")</td>
<td colspan="1" class="group">$messages.getString("oneclass.testresult")</td>
</tr>

10.效果图



 11、通过Apache ANT构建测试,生成reportng html report

                    修改配置文件build.xml,ant运行即可

                   

                  通知执行ant ,发现有错误,提示:无法找到org.uncommons.reportng.HTMLReporter里面的类文件,这里是因为没有把reportng的那几个jar包放到libs文件夹                   中,放进去后,即可以正常执行ant

                   

                   test-output文件中可以查看生成的html测试报告。

 

12、用jenkins执行测试构建时,jenkins中测试报告可能显示不全,这里需要改变一下jenkins的启动方式:

                      默认方式为:java -jar jenkins.war

                      改为: java -Dhudson.model.DirectoryBrowserSupport.CSP= -jar jenkins.war

                      这个问题可参见下面这位大神的文章:

                      http://www.cnblogs.com/xiaomingtx/p/5669798.html


  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值