allure使用

1、官网地址

https://allurereport.org/

2、环境准备

安装 Node.js(Allure3 需要)

https://nodejs.org/ 安装 LTS 版

复制代码
node -v
npm -v

安装 Allure 3 CLI

复制代码
npm install -g allure

验证:

复制代码
allure --version

3、代码

Maven 配置(pom.xml)

复制代码
<dependencies>
    <!-- JUnit 5 -->
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>5.9.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>5.9.2</version>
        <scope>test</scope>
    </dependency>

    <!-- Allure 3 兼容 JUnit 5 -->
    <dependency>
        <groupId>io.qameta.allure</groupId>
        <artifactId>allure-junit5</artifactId>
        <version>2.25.0</version>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>3.1.2</version>
            <configuration>
                <!-- 测试结果输出目录,Allure 3 会读取它 -->
                <systemProperties>
                    <allure.results.directory>${project.basedir}/allure-results</allure.results.directory>
                </systemProperties>
            </configuration>
        </plugin>
    </plugins>
</build>

写一个最简单的测试类

复制代码
import io.qameta.allure.Allure;
import io.qameta.allure.Step;
import org.junit.jupiter.api.Test;

public class MyFirstTest {

    @Test
    public void testDemo() {
        step1();
        step2();
        step3();
    }

    @Step("第一步:打开系统")
    public void step1() {
        Allure.attachment("说明", "这是一个Allure3的测试演示");
    }

    @Step("第二步:输入数据")
    public void step2() {
    }

    @Step("第三步:验证结果")
    public void step3() {
    }
}

4、运行测试(生成 allure-results)

进入项目根目录,执行:

复制代码
mvn clean test

运行后,你会看到项目根目录自动生成:

复制代码
allure-results/

这就是 Allure 3 需要的原始数据。

5、用 Allure 3 打开报告

方法 1:直接启动网页服务(推荐)

复制代码
> allure serve allure-results
Allure is running on http://localhost:6703

自动打开浏览器,显示 Allure 3 全新界面报告

方法 2:生成静态 HTML 报告

复制代码
> allure generate  allure-results

> allure open
Allure is running on http://localhost:7031

报告

可以改成中文

  • 统计卡片:总用例数、通过 / 失败 / 跳过 / 错误数、通过率、执行总时长。

  • 趋势图:历史构建通过率、耗时变化(需多次执行)。

  • 执行器信息:运行环境、执行者、CI 构建号。

  • 环境信息(Environment):OS、浏览器、JDK、依赖版本等(需手动配置)。

相关推荐
byxdaz17 分钟前
jeston平台交叉编译Poppler库与预览pdf文件
数据库
SilicoCode23 分钟前
江科大STM32入门:FLASH闪存详解——从结构原理到读写保护
数据库·mongodb
一个有温度的技术博主1 小时前
DeepSeek Harness 深度解析:与 LangChain / LangGraph 的本质区别
数据库·oracle·langchain·harness
Wang's Blog2 小时前
PostgreSQL笔记4: 市场地位、生态全景与行业应用实践
数据库·笔记·postgresql
隔窗听雨眠3 小时前
Oracle误Truncate操作恢复:从原理到实战的完整指南
数据库·oracle
Lethehong3 小时前
MySQL迁移如何做到零改造?四层兼容方案详解
数据库·mysql·adb
Json____3 小时前
五金制品行业-企业官网源码
java·大数据·数据库·企业站·wwwoop.com
深念Y5 小时前
Opencode Event 表写入优化方案
数据库·人工智能·ai·node.js·bug·优化·opencode
竹枝溪5 小时前
MySQL进阶:约束、多表设计、多表查询与事务
java·数据库·mysql·事务·子查询·acid·多表查询
weixin_431600446 小时前
NestJS 入门(9):连上数据库,SQL 写在哪?
数据库·后端·sql·学习·nest.js