更多课程 选择中心

软件测试培训
达内IT学院

400-111-8989

ReportNG美化测试报告--TestNG 入门教程(八)


众所周知,testNG自带的report不太美观,所以我们这里用到了reportNG来生成report,加入reportNG很简单,只需在pom.xml中加入以下配置

<dependencies>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.9.6</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
        </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-beta5</version>
        </dependency>
    </dependencies>

下面是配置maven-surefire-plugin并加入reportNG listenser

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.18.1</version>
                <configuration>
                    <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>
                    <suiteXmlFiles>
                        <suiteXmlFile>practice11.xml</suiteXmlFile>
                    </suiteXmlFiles>
                    <workingDirectory>target/</workingDirectory>
                </configuration>
            </plugin>
        </plugins>
    </build>

这里要将defaultListener设置为false,下面配置了两个listener,一个是HTMLReport,用来生成HTML格式的Report,别一个是JUnitXMLReporter,这个是用来生成xml格式的report,用于jekins服务器;practice11.xml即为即将运行的TestNG xml。

然后运行maven test,生成的报告会在target/目录下。

有了报告以后,我们会想,能不能在case执行的过程中将一些重要的log信息也输出到report中呢?

testNG中有这样一个类:Reporter,就是专门做这个工作的。

@Test
    public void test1(){
        Reporter.log("This is test1");
    }

这样生成的报告就既美观又实用了。

除了ReportNG外,我们还可以使用testNG-xslt

预约申请免费试听课

填写下面表单即可预约申请免费试听! 怕学不会?助教全程陪读,随时解惑!担心就业?一地学习,可全国推荐就业!

上一篇:测试报告--TestNG 入门教程(七)
下一篇:概述--Selenium自动化(一)

测试报告--TestNG 入门教程(七)

特性三--TestNG 入门教程(六)

特性二--TestNG 入门教程(五)

特性一--TestNG 入门教程(四)

  • 扫码领取资料

    回复关键字:视频资料

    免费领取 达内课程视频学习资料

Copyright © 2023 Tedu.cn All Rights Reserved 京ICP备08000853号-56 京公网安备 11010802029508号 达内时代科技集团有限公司 版权所有

选择城市和中心
黑龙江省

吉林省

河北省

陕西省

湖南省

贵州省

云南省

广西省

海南省