【转载】使用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包

4.更改eclipse设置

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

6.设置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();
        }
    }
复制代码

 

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

更改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;
     }
复制代码

 8.teng的xml文件

复制代码
<?xml version="1.0" encoding="UTF-8"?>
<suite name="测试用例集" parallel="false">
<listeners>
<listener class-name="org.uncommons.reportng.HTMLReporter" />
<listener class-name="org.uncommons.reportng.JUnitXMLReporter" />
</listeners>
  <test verbose="8" name="TestNgrepotng">
    <classes>
      <class name="com.reprot.TestNgrepotng"/>
    </classes>
  </test> <!-- Test -->
    <test verbose="8" name="Test22">
    <classes>
      <class name="com.reprot.Test22"/>
    </classes>
  </test>
</suite> <!-- Suite -->
复制代码

 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>

******************************************************************************************************************************************
作者:乔叶叶
博客地址:http://www.cnblogs.com/qiaoyeye/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
**********************************************************************************************************************************

转载于:https://www.cnblogs.com/R9527/articles/5104700.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值