TestNG修改reportNG输出description

前言

在使用reportNG来输出TestNG的报告的时候,出来的报告中method都是按照名称来列的,但是这样对于我们来说很不好看,最好是能够加点中文,那么就想到了可以使用其description属性来展示其中文说明,那就需要修改下源码了;

修改源代码

1、下载源码

去reportNG的官网下载下来源码:https://reportng.uncommons.org/
在这里插入图片描述
将其导入到eclipse中;

2、修改代码:

要修改的文件的位置:
在这里插入图片描述
打开后修改其第十四行代码:

<span class="description" title="$testResult.method.description">$testResult.name$testInstanceName ($testResult.method.description)</span>

说明:
$testResult.method.description即为抓取description属性,注意小括号前要加个英文空格,否则生成的报告无法把描述带出来;

3、打包

由于源码中已经放置了build.xml(不要看有pom.xml,不能用maven打包的),故直接使用ant打包,方法不再详述,记得要将版本改一下,如下:
在这里插入图片描述

5、加入项目

由于使用的maven工程,所以这个打好的reportNG的包不好直接使用,故先使用cmd命令将其加入本地仓库,如下:
mvn install:install-file -DgroupId=org.uncommons -DartifactId=reportng -Dversion=1.1.6 -Dfile=E:\jarHome\reportng-1.1.6.jar -Dpackaging=jar
(此代码中只用修改-Dfile=后边的jar包的路径即可);
而后在项目的pom中加入如下依赖:

<dependency>
      <groupId>org.uncommons</groupId>
      <artifactId>reportng</artifactId>
      <version>1.1.6</version>
    </dependency>
    <dependency>
      <groupId>org.apache.velocity</groupId>
      <artifactId>velocity</artifactId>
      <version>1.7</version>
    </dependency>

velocity是reportNG需要的包,故一定要带上;

6、用例

之后在书写用例的时候记得加上description:

@Test(groups={smoke,normal,all}, description="创建课程")

这样出来的报告中,就会包含description了:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/df0128/article/details/88052286