zoukankan      html  css  js  c++  java
  • reportNg+maven测试报告

      用了testNg已经一年了,jenkins上生成的测试报告很方便,但是不知道具体是怎么生成的,捣鼓了一天终于整明白了,在这里记录一下,免得以后用到时候还得重新弄。

    一、pom配置

           <dependency>
                <groupId>org.testng</groupId>
                <artifactId>testng</artifactId>
                <version>6.14.3</version>
            </dependency>
    
            <dependency>
                <groupId>org.uncommons</groupId>
                <artifactId>reportng</artifactId>
                <version>1.1.4</version>
                <exclusions>
                    <exclusion>
                        <groupId>org.testng</groupId>
                        <artifactId>testng</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <groupId>com.google.inject</groupId>
                <artifactId>guice</artifactId>
                <version>4.0</version>
            </dependency>
    
            <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.22.2</version>
                    <configuration>
                        <suiteXmlFiles>
                            <suiteXmlFile>src/main/resources/testng.xml</suiteXmlFile>
                        </suiteXmlFiles>
    
                        <systemPropertyVariables>
    <!--                        <serviceProperty>src/main/resources/config.prop</serviceProperty>-->
                        </systemPropertyVariables>
                        <useSystemClassLoader>true</useSystemClassLoader>
                        <testFailureIgnore>true</testFailureIgnore>
                        <properties>
                            <property>
                                <name>usedefaultlisteners</name>
                                <value>false</value>
                            </property>
                            <property>
                                <name>listener</name>
                                <value>org.uncommons.reportng.HTMLReporter, org.uncommons.reportng.JUnitXMLReporter</value>
                            </property>
                        </properties>
    <!--                    <workingDirectory>test-output/</workingDirectory>-->
                        <forkMode>once</forkMode>
                        <argLine>-Dfile.encoding=UTF-8</argLine>
                    </configuration>
                </plugin>

    二、中文乱码问题

      有两种方法解决问题:

      1. 下载reportNg源码修改AbstractReporter类的generateFile方法,如下:

        参考地址:https://www.jianshu.com/p/658ec96bc0f6

        protected void generateFile(File file,
                                    String templateName,
                                    VelocityContext context) throws Exception
        {
            // Writer writer = new BufferedWriter(new FileWriter(file));
            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();
            }
        }

      2. 下载reportNg.jar,下载地址:http://pan.baidu.com/s/1pLdZdt5,密码:fctu  

      3. 无论哪种方法你得到的都是jar文件,需要安装到你的仓库才能在pom中引用。

      打开cmd,执行命令: mvn install:install-file -Dfile=jar包的位置 -DgroupId=groupId -DartifactId=artifactId -Dversion=version -Dpackaging=jar ,居然报错了~~~

      在idea的terminal内执行:mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=D: eportng-1.1.4.jar,成功了~,但是不知道为啥上边的方法报错,求大神指导

      4. 运行case中文不会乱码了,如果还是乱码,可能是你的IDE控制台编码格式问题

    三、测试报告生成路径

      1. mvn test生成报告路径是target目录下,如图:

      

      2. 直接运行testng.xml生成测试报告的路径是:test-output

      3. 因为在pom里配置了HTMLReporter和JUnitXMLReporter监听器,所以会生成xml和html两种测试报告,html更易于测试人员了解测试执行情况,以为大部分人都只关心执行失败的case。xml的测试报告便于开发人员做其他处理,获取想要的信息,个人理解~

  • 相关阅读:
    二分图 洛谷P2055 [ZJOI2009]假期的宿舍
    并查集 洛谷P1640 [SCOI2010]连续攻击游戏
    贪心 洛谷P2870 Best Cow Line, Gold
    贪心 NOIP2013 积木大赛
    快速幂 NOIP2013 转圈游戏
    倍增LCA NOIP2013 货车运输
    树形DP 洛谷P2014 选课
    KMP UVA1328 Period
    动态规划入门 BZOJ 1270 雷涛的小猫
    KMP POJ 2752Seek the Name, Seek the Fame
  • 原文地址:https://www.cnblogs.com/weiyulin/p/11727411.html
Copyright © 2011-2022 走看看