IDEA MAVEN 配置TESTNG 和 REPORTNG并输出测试报告

本文介绍了在IDEA+JAVA+MAVEN环境下配置TESTNG和REPORTNG的方法。包括配置pom插件,处理包报错问题,可删除尾缀为:lastupdate文件或自行下载插件。配置完成后创建用例,配置监听器,在maven中运行test,最后可在指定路径查看报告。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这里写自定义目录标题

一 前提条件

IDEA----JAVA—MAVEN 在网上有很多的教程,这里不再重复

配置TESTNG和REPORTNG的pom

<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>4.11</version>
  <scope>test</scope>
</dependency>



<dependency>
  <groupId>org.junit.jupiter</groupId>
  <artifactId>junit-jupiter-api</artifactId>
  <version>RELEASE</version>
  <scope>compile</scope>
</dependency>


<!-- https://mvnrepository.com/artifact/org.apache.velocity/velocity -->
<dependency>
  <groupId>org.apache.velocity</groupId>
  <artifactId>velocity</artifactId>
  <version>1.7</version>
</dependency>
 <dependency>
  <groupId>org.testng</groupId>
  <artifactId>testng</artifactId>
  <version>6.14.3</version>
  <scope>test</scope>
</dependency>

<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>


<!-- https://mvnrepository.com/artifact/com.google.inject/guice -->
<dependency>
  <groupId>com.google.inject</groupId>
  <artifactId>guice</artifactId>
  <version>4.2.2</version>
</dependency>

插件:
注意:maven插件已声明maven-surefire-plugin请删除

      <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>2.22.1</version>
      <configuration>
        <suiteXmlFiles>
          <suiteXmlFile>testng.xml</suiteXmlFile>
        </suiteXmlFiles>
        <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>

配置完成后maven提示导入,导入所有
在这里插入图片描述

导入完毕后查看,如果遇到包报错,进入maven下载包的路径:
在这里插入图片描述
一般文件夹中只存在一个文件尾缀为:lastupdate文件,将其删除,maven会重新提示,提示后点击下载,等待下载完成,报错消除
在这里插入图片描述
如果还不能消除,使用http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-surefire-plugin/此地址自己下载,这个链接为maven工具插件,其他插件通过url中的路径自己选择,下载文件包含以下格式
在这里插入图片描述

所有内容配置完毕后创建用例:
在这里插入图片描述
再运行配置中配置监听器:

在这里插入图片描述
再maven中运行test
在这里插入图片描述
再target中的surefire-reports-------html中的index中查看报告
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值