标签:测试报告 results testng maven allure org testNg public
1. 安装Allure
- allure下载 <Assets>标签下选择对应的安装包
- 添加环境变量 将allure的bin目录添加到系统path中,注意分隔符;
2. 工程文件
① 工程目录
|
④ pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.csj2018</groupId>
<artifactId>AllureReport</artifactId>
<version>1.0-SNAPSHOT</version>
<!--不打jar包,没用就删掉 -->
<packaging>jar</packaging>
<name>Archetype - AllureReport</name>
<url>http://maven.apache.org</url>
<properties>
<!-- 文件拷贝时的编码 -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<!-- 编译时的编码 -->
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
<aspectj.version>1.9.22.1</aspectj.version>
<maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format>
</properties>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.10.2</version>
</dependency>
<!-- Allure的jar包 -->
<!-- https://mvnrepository.com/artifact/io.qameta.allure/allure-testng -->
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-testng</artifactId>
<version>2.29.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-deploy-plugin -->
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.1.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<!-- <version>3.13.0</version> -->
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version><!-- 仓库内多版本 3.5.2 -->
<configuration>
<skipTests>false</skipTests>
<testFailureIgnore>true</testFailureIgnore>
<!-- UTF-8编码-->
<argLine>-Dfile.encoding=UTF-8</argLine>
<argLine>
<!-- 配置拦截器 -->
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
</argLine>
<systemProperties>
<property>
<!-- 配置 allure 结果存储路径 -->
<name>allure.results.directory</name>
<value>${project.build.directory}/allure-results</value>
</property>
</systemProperties>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.9.22.1</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
|
② 测试代码
package com.singledog.testng;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
public class Case5 {
@Test(dataProvider = "datas")
public void test1(String animal, String name){
System.out.println("Case5 ... test1 ...");
System.out.printf("这是%s,它的名字是%s\n",animal,name);
}
@DataProvider(name = "datas")
public Object[][] datas(){
Object[][] datas = {
{"猫","汤姆"},
{"老鼠","杰瑞"},
};
return datas;
}
@Test(groups = "回归")
public void testMain(){
System.out.println("主页面");
}
@Test(groups = "回归")
public void testSearch(){
System.out.println("search func");
}
}
|
③ testng.xml
<?xml version="1.0" encoding="utf-8" ?>
<suite name="棋牌项目" parallel="false">
<test name="模块1">
<groups>
<run>
<include name="回归" />
</run>
</groups>
<classes>
<class name="com.singledog.testng.Case5" />
</classes>
</test>
</suite>
|
3. 执行测试 mvn clean test
执行命令后,会在target下生成allure-results目录,里面的json数据就是测试结果文件
4. 生成测试报告
方式一:启用allure服务,生成在线报告
cmd切换到工程目录,执行命令allure serve target/allure-results,会自动打开浏览器
|
方式二:生成本地静态页面
cmd切换到target目录,执行命令allure generate allure-results/ -o report/html --clean
|
标签:测试报告,
results,
testng,
maven,
allure,
org,
testNg,
public
From: https://www.cnblogs.com/csj2018/p/9426474.html