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、依赖版本等(需手动配置)。

相关推荐
weixin_397574094 分钟前
用自然语言查数据库出图表靠谱吗?一次智能问数实践复盘
数据库
字节跳动开源2 小时前
Viking AI 搜索 CLI 正式发布:会说话,就能做搜索推荐
数据库·人工智能·开源
TechWJ3 小时前
数据库在公司内网,出差路上想查数据怎么办?
服务器·数据库·mariadb
我是一颗柠檬3 小时前
【MySQL全面教学】MySQL事务与ACID Day9(2026年)
数据库·后端·mysql
橙子圆1233 小时前
Redis知识9之集群
数据库·redis·缓存
BlackHeart12033 小时前
【SQL】Oracle中序列(Sequence)作为默认值引发的ORA-00979
数据库·sql·oracle
bug菌4 小时前
【SpringBoot 3.x 第254节】夯爆了,数据库访问性能优化实战详解!
数据库·spring boot·后端
xxl大卡4 小时前
MySQL的执行流程
数据库·mysql
chicheese4 小时前
MySQL优化实践:选错JOIN 驱动表,性能相差几十倍
数据库·mysql
無限進步D4 小时前
MySQL 单行函数
数据库·mysql