testng 整合 allure 生成自动化测试报告

本贴最后更新于 1451 天前,其中的信息可能已经时移世异

1、在项目中导入testng和allure2坐标和对应设置

<properties>
	<maven.compiler.target>1.8</maven.compiler.target>
	<maven.compiler.source>1.8</maven.compiler.source>
	<!-- 文件拷贝时的编码 -->
	<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.2</aspectj.version>
</properties>


<!-- testng maven坐标 -->
<dependency>
	<groupId>org.testng</groupId>
	<artifactId>testng</artifactId>
	<version>6.8.8</version>
</dependency>

<!-- allure2 maven坐标 -->
<dependency>
	<groupId>io.qameta.allure</groupId>
	<artifactId>allure-testng</artifactId>
	<version>2.6.0</version>
	<scope>test</scope>
</dependency>

2、加入maven-surefire-plugin插件并进行配置

<build>
	<plugins>
		<plugin>
			<!-- maven-surefire-plugin 配合testng/junit执行测试用例的maven插件 -->
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-surefire-plugin</artifactId>
			<version>2.22.1</version>
			<configuration>
				<!-- 测试失败后是否忽略并继续测试 -->
				<testFailureIgnore>true</testFailureIgnore>
				<suiteXmlFiles>
					<!-- testng配置文件名称  -->
					<suiteXmlFile>testng.xml</suiteXmlFile>
				</suiteXmlFiles>
				<!--设置参数命令行 -->
				<argLine>
					<!-- UTF-8编码 -->
					-Dfile.encoding=UTF-8
					<!-- 配置拦截器 -->
					-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>
			</configuration>
			<dependencies>
				<!-- aspectjweaver maven坐标 -->
				<dependency>
					<groupId>org.aspectj</groupId>
					<artifactId>aspectjweaver</artifactId>
					<version>${aspectj.version}</version>
				</dependency>
			</dependencies>
		</plugin>
	</plugins>
</build>

3、使用 clean test 命令运行项目(这里使用eclipse为例)
image.png
image.png

4、使用 io.qameta.allure:allure-maven:serve 命令启动allure内置服务,运行完成之后就会弹出allure页面
image.png
image.png
image.png

5、查看allure自动生成的报告页面
image.png

6、选择Graphs查看图形结构
image.png

7、选择Behaviors 查看每个用例的详情信息
image.png

8、后记


allure还可以和Jenkins集成,在Jenkins安装allure插件能够显示更全更详细的信息,比如趋势、历史记录、分类等等。

1 操作
luojie 在 2020-08-06 17:44:12 更新了该帖
回帖
请输入回帖内容 ...