You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Serenity/Allure集成问题:自动化测试执行两次

解决Serenity与Allure共存时测试套件重复运行的问题

这种情况大概率是因为Serenity和Allure的Maven插件都绑定了verify阶段,各自触发了测试执行,导致测试被重复运行两次。下面给你一套可行的解决方案:

核心思路

借助Serenity官方提供的Allure集成适配器,让一次测试执行同时生成两种报告所需的原始数据,再由对应插件分别生成报告,从根源避免重复触发测试。

具体配置步骤

1. 添加Serenity-Allure集成依赖

在pom.xml的<dependencies>中加入集成依赖,这样Serenity执行测试时会自动生成Allure兼容的测试结果文件:

<dependency>
    <groupId>net.serenity-bdd</groupId>
    <artifactId>serenity-allure</artifactId>
    <version>${serenity.version}</version>
    <scope>test</scope>
</dependency>

2. 调整Maven插件绑定逻辑

修改插件的阶段绑定,确保只有Serenity插件负责触发测试,Allure插件仅在测试完成后生成报告:

配置Serenity插件

保持Serenity插件绑定到verify阶段,负责执行测试并生成Serenity报告:

<plugin>
    <groupId>net.serenity-bdd.maven.plugins</groupId>
    <artifactId>serenity-maven-plugin</artifactId>
    <version>${serenity.maven.version}</version>
    <executions>
        <execution>
            <id>serenity-reports</id>
            <phase>verify</phase>
            <goals>
                <goal>aggregate</goal>
            </goals>
        </execution>
    </executions>
</plugin>

配置Allure插件

修改Allure插件的触发阶段,让它在测试完成后再生成报告,同时禁用自动测试触发:

<plugin>
    <groupId>io.qameta.allure</groupId>
    <artifactId>allure-maven</artifactId>
    <version>${allure.maven.version}</version>
    <executions>
        <execution>
            <id>allure-report</id>
            <!-- 绑定到测试完成后的阶段,确保测试数据已生成 -->
            <phase>post-integration-test</phase>
            <goals>
                <goal>report</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <!-- 指定Serenity生成Allure结果的目录 -->
        <resultsDirectory>${project.build.directory}/allure-results</resultsDirectory>
    </configuration>
</plugin>

3. 验证执行效果

执行mvn clean verify,此时测试只会运行一次,执行完成后:

  • Serenity报告默认生成在target/site/serenity目录下
  • Allure报告可通过mvn allure:serve启动本地服务查看,或通过mvn allure:report生成静态报告到target/site/allure-maven

额外注意事项

  • 确保serenity.version与allure.maven.version版本兼容,建议参考Serenity官方文档的版本匹配说明
  • 如果之前手动配置过Allure的测试监听类,记得移除,避免与Serenity的集成逻辑冲突

内容的提问来源于stack exchange,提问作者ampc

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 06:57:39