zoukankan      html  css  js  c++  java
  • MacOS + Idea配置 Maven + ReportNG

    用testng做接口自动化,testng自带的报告模板不是特别美观,于是找到了ReportNG。

    一、在maven的pom.xml中添加ReportNG(最新版本为1.1.4)

    <dependencies>
        <dependency>
            <groupId>org.uncommons</groupId>
            <artifactId>reportng</artifactId>
            <version>1.1.4</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.testng</groupId>
                    <artifactId>testng</artifactId>
                </exclusion>
            </exclusions>
        </dependency></dependencies>

    备注:使用TestNG6.0+可能会遇到“ClassNotFoundExpection:com.google.inject.Module”问题,这里必须添加Guice,同样在pom.xml文件中继续添加

    <dependency>
        <groupId>com.google.inject</groupId>
        <artifactId>guice</artifactId>
        <version>3.0</version>
        <scope>test</scope>
    </dependency>

    二、添加Surefire插件

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.5</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>
                    <workingDirectory>target/</workingDirectory>
                </configuration>
            </plugin>
        </plugins>
    </build>

    至此,最基本的ReportNG报告模板以及添加完成

    三、演示

    这里以我之前写的一个Http接口测试为例子:

    http://www.cnblogs.com/testJocab/p/5438585.html

    1.打开终端,进入IDEA测试项目根目录

    2.运行命令:mvn clean test,以下为输出内容

    [INFO] Scanning for projects...
    [INFO]                                                                         
    [INFO] ------------------------------------------------------------------------
    [INFO] Building maven 1.0-SNAPSHOT
    [INFO] ------------------------------------------------------------------------
    Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom
    Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom (4 KB at 1.0 KB/sec)
    [INFO] 
    [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ maven ---
    [INFO] Deleting /Users/zhangbin/IdeaProjects/HttpTest/target
    [INFO] 
    [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ maven ---
    [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
    [INFO] Copying 0 resource
    [INFO] 
    [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ maven ---
    [INFO] Nothing to compile - all classes are up to date
    [INFO] 
    [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ maven ---
    [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
    [INFO] skip non existing resourceDirectory /Users/zhangbin/IdeaProjects/HttpTest/src/test/resources
    [INFO] 
    [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ maven ---
    [INFO] Changes detected - recompiling the module!
    [WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
    [INFO] Compiling 2 source files to /Users/zhangbin/IdeaProjects/HttpTest/target/test-classes
    [INFO] 
    [INFO] --- maven-surefire-plugin:2.5:test (default-test) @ maven ---
    Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-toolchain/2.0.9/maven-toolchain-2.0.9.jar
    Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-toolchain/2.0.9/maven-toolchain-2.0.9.jar (38 KB at 14.2 KB/sec)
    Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-testng/2.5/surefire-testng-2.5.pom
    Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-testng/2.5/surefire-testng-2.5.pom (3 KB at 1.8 KB/sec)
    Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-providers/2.5/surefire-providers-2.5.pom
    Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-providers/2.5/surefire-providers-2.5.pom (2 KB at 2.1 KB/sec)
    Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-testng/2.5/surefire-testng-2.5.jar
    Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-testng/2.5/surefire-testng-2.5.jar (27 KB at 8.3 KB/sec)
    [INFO] Surefire report directory: /Users/zhangbin/IdeaProjects/HttpTest/target/surefire-reports
    
    -------------------------------------------------------
     T E S T S
    -------------------------------------------------------
    Running TestSuite
    =======This is BeforeClass=======
    http://gateway.zitech.com/gw/oauthentry/study.scene/1.0/getbysid?access_token=bb801ee6b9983c7f893473fd6a313ad2&subject_id=1
    http://gateway.zitech.com/gw/oauthentry/study.scene/1.0/getbysid?access_token=bb801ee6b9983c7f893473fd6a313ad2&subject_id=1%2C2
    http://gateway.zitech.com/gw/oauthentry/study.scene/1.0/getbysid?access_token=bb801ee6b9983c7f893473fd6a313ad2&subject_id=123
    http://gateway.zitech.com/gw/oauthentry/study.scene/1.0/getbysid?access_token=bb801ee6b9983c7f893473fd6a313ad2&subject_id=
    This is afterClass
    Tests run: 4, Failures: 4, Errors: 0, Skipped: 0, Time elapsed: 10.556 sec <<< FAILURE!
    
    Results :
    
    Failed tests: 
      getUri(HttpGetTest)
      getUri(HttpGetTest)
      getUri(HttpGetTest)
      getUri(HttpGetTest)
    
    Tests run: 4, Failures: 4, Errors: 0, Skipped: 0
    
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 26.159 s
    [INFO] Finished at: 2016-05-07T16:59:59+08:00
    [INFO] Final Memory: 18M/176M
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.5:test (default-test) on project maven: There are test failures.
    [ERROR] 
    [ERROR] Please refer to /Users/zhangbin/IdeaProjects/HttpTest/target/surefire-reports for the individual test results.
    [ERROR] -> [Help 1]
    [ERROR] 
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR] 
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

    从输出结果可以看出,这个接口是出现问题的

    3.查看Html报告

    输出结果中有这么一句:

    Please refer to /Users/zhangbin/IdeaProjects/HttpTest/target/surefire-reports for the individual test results.

    所以我们的Html报告即在项目文件夹中的target、surefire-reports文件夹中,截图我就不再附上了。

  • 相关阅读:
    vue 路由跳转返回上一级
    js中Let和Var的区别
    JS实现电话号码校验座机:区号号码、或11位手机号
    VUE 监听 对象属性值变化的三种方式
    vue中computed的用法
    elementUI中input输入框,强制输入数字,并限制输入长度
    C++中__int64用法
    WIN10计算器设计可能出现的坑
    跳转acticity
    asp.net邮件发送
  • 原文地址:https://www.cnblogs.com/testJocab/p/5468785.html
Copyright © 2011-2022 走看看