Allure是一个Java语言开发的轻量级、灵活的、支持多语言(pytest、JavaScript、PHP、ruby等)、支持多平台的测试报告工具;能够提供详尽的测试报告、测试步骤、log、数据统计报告等,且可以集成到Jenkins。
官方地址:https://allurereport.org/docs/
安装配置
1.commandline包下载地址:https://repo1.maven.org/maven2/io/qameta/allure/allure-commandline/
2.解压allure-commandline包
3.配置环境变量:D:\allure\allure-commandline-2.34.1\allure-2.34.1\bin
4.cmd执行命令allure --version,能够查询到版本号,说明环境变量配置正确
引入依赖
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-junit5</artifactId>
<version>2.13.6</version>
<scope>test</scope>
</dependency>
依赖的作用域
在Maven中,compile和test是两种不同的依赖作用域
- compile表示依赖项在编译、测试和运行时都需要被包含在类路径中,这意味着该依赖项将被打包到最终构件中,并且在运行时也可以被其他模块引用;
- test表示该依赖项只在测试阶段使用,不会被打包到最终构建中,它仅在编译和执行测试代码时使用。
如下依赖表示allure-junit5库将被包含在编译、测试和运行时的classpath中,并且在运行时可以被应用程序代码访问。
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-junit5</artifactId>
<version>2.13.6</version>
<scope>compile</scope>
</dependency>
生成测试报告
操作步骤
1.在IDEA终端执行命令:mvn clean test
mvn clean test #运行所有用例
mvn clean -Dtest=TestDemo test #运行指定类
mvn clean package -Dtest=<文件名> test #运行指定一个或多个文件,多个用逗号隔开
mvn clean package -Dtest=<文件名1>,<文件名2>.... test
2.测试结果保存在allure-results文件
3.在IDEA终端执行命令,打开测试报告
allure serve ./allure-results
定制allure测试报告
方法 | 参数值 | 参数说明 |
---|---|---|
@Epic | 模块名称 | 大模块名称 |
@Feature | 子模块名称 | 相当于一个功能,一个大模块 |
@Story | 用例名称 | 相当与功能下的一个场景 |
@DisplayName | 用例标题 | 用例标题 |
@issue | 缺陷地址 | 对应缺陷管理系统里边的缺陷地址 |
@Description | 用例描述 | 用例的详细描述 |
@Step | 操作步骤 | 用例的操作步骤 |
@Severity | 用例等级 | blocker、critical、normal、minor、trivial |
@Link | 定义链接 | 用于定义一个需要在测试报告中展示的链接 |
Allure.addAttachment | 附件 | 添加测试报告附件(文本、图片、视频等) |
@Feature("登录注册功能")
public class AllureReportDemoTest {
@Test
@Story("注册")
@DisplayName("注册功能")
@Description("验证注册功能是否正常")
public void test1(){
System.out.println("第一条用例");
}
@Test
@Story("登录")
@DisplayName("登录功能")
@Description("验证登录功能是否正常")
public void test2(){
int a=2;
int b=2;
int total=5;
Allure.step("期望的是:"+total+"实际是:"+(a+b));
Assertions.assertEquals(total,a+b);
System.out.println("第二条用例");
}
}