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文件夹中,截图我就不再附上了。

时间: 2024-08-18 09:59:35

MacOS + Idea配置 Maven + ReportNG的相关文章

IDEA 配置maven

编写Maven的settings.xml文件内容如下 引入阿里镜像和maven在中国的中央仓库镜像 <?xml version="1.0" encoding="UTF-8"?> <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:sc

eclipse配置maven

maven安装配置成功后开始在Eclipse中配置maven,点击eclipse菜单栏Help->Eclipse Marketplace搜索关键字maven到插件Maven Integration for Eclipse并点击安装即可,如下图: 安装完毕后,点击重启eclipse 重启后,为了使得Eclipse中安装的Maven插件,同windows中安装的那个相同,需要让eclipse中的maven重新定位一下,点击Window -> Preference -> Maven ->

Maven(一)——如何在Windows操作系统中安装配置Maven环境

今天难得的周末,借此难的机会总结一下关于maven的一些操作: 1.在安装maven之前要确认计算机已经安装并配置了JDK: 2.下载maven: maven-3.0.3:http://download.csdn.net/detail/wangshuxuncom/7367413 maven-3.0.5:http://download.csdn.net/detail/wangshuxuncom/7551799 说明:上述资源均免费下载 这里选择maven-3.0.3来演示安装.将maven-3.0

Mac上配置maven+eclipse+spark开发环境

1.安装jdk 2.下载scala-ide.官网:http://scala-ide.org 3.安装maven 4.在eclipse中,配置maven的安装了路径.偏好设置--->maven--->installpath 5.修改maven的镜像文件,即setting.txt中的mirror.具体修改为如下: <mirrors> <mirror> <id>alimaven</id> <name>aliyun maven</nam

配置Maven并新建项目遇到的问题

配置Maven的方法:http://www.iteye.com/topic/1127097 遇到的问题:新建Maven项目后报错:Could not get the value for parameter encoding for plugin execution default- resources 解决方法: 解决: 问题: Could not get the value for parameter encoding for plugin execution default-resource

十分钟教程,eclipse配置maven + 创建maven

若没有安装maven插件,我们需要先安装maven插件. 安装maven插件 eclipse安装插件有常用两种方式,在线方式和离线方式.这两种安装方式我建议大家使用离线方式,离线方式更加方便,简单,这两中安装方式网上的资料很多,也非常简单,我就不再累述了.给大家推荐一篇即可: 安装Eclipse Maven插件的几种方法 配置maven 配置maven安装目录 依次打开Window –> Perferences –> Maven ,展开Maven的配置界面,如上图: http://www.na

使用IDEA配置Maven搭建开发框架

一.配置Maven环境 1.下载Maven 下载链接http://maven.apache.org/download.cgi 2.下载完成解压压缩包并创建本地仓库文件夹 3.打开解压缩文件,配置本地仓库路径 4.配置Maven环境变量 5.在cmd中查看maven是否配置正确 在cmd中输入mvn -v命令查看 二.在IntelliJ IDEA中配置Maven 打开-File-Settings 三.新建maven JAVAWEB项目 1.打开-File-New-Project Next Next

IDEA配置maven(配置阿里云中央仓库)

前言 idea配置maven后如果不修改中央仓库地址创建maven则出奇的慢,不管你用MyEclipse还是idea都慢的不要不要的,实在不能忍受. 这种条件下发现一个阿里云中央仓库来点福利,有福利了就必须给阿里云点个赞. 配置Maven 下载maven,我用的版本是3.3.9. 配置环境变量.设置Repository. 这时你创建maven项目时settings.xml默认是用/User/.m2/settings.xml. 打开maven/conf/settings.xml, 找到mirror

slf4j+log4j配置(Maven)

首先配置Maven依赖 <!-- http://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12 --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.7.21</version> </dependency> 代