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

多模块Maven项目Serenity BDD JUnit Screenplay报告聚合异常求助

解决Serenity多模块聚合报告仅显示单个模块Requirements/Features/Stories的问题

我之前在搭建Serenity多模块测试项目时也踩过完全一样的坑,结合你用的Serenity 2.0.81、Screenplay模式+多模块Maven的场景,咱们一步步排查解决:

1. 核心问题:子模块输出目录重复导致文件覆盖

你给所有子模块指定了相同的serenity.outputDirectory=c:/temp/uireport,这会让后运行的子模块直接覆盖先运行模块的serenity.json等核心报告文件——而Requirements/Features/Stories的聚合数据正是从这些文件里提取的,测试用例和标签因为是在聚合阶段单独收集的元数据,所以不受影响。

修复方案:

给每个子模块配置独立的临时输出目录,让父模块统一聚合这些目录的内容:

  • 子模块的serenity.properties修改为Serenity默认路径(每个子模块的报告存在自己的target下,互不干扰):
    serenity.outputDirectory=target/site/serenity
    
  • 父模块根目录新建serenity.properties,明确指定要聚合的所有子模块报告路径:
    serenity.aggregate.source=demo_one/target/site/serenity,demo_two/target/site/serenity,demo_three/target/site/serenity
    

2. 检查父模块Maven插件的配置有效性

你说各级pom都配置了serenity-maven-plugin的aggregate目标,但要确保父模块的插件配置是直接放在<build><plugins>节点下,而非<pluginManagement>,并且绑定到正确的生命周期阶段:

<build>
  <plugins>
    <plugin>
      <groupId>net.serenity-bdd.maven.plugins</groupId>
      <artifactId>serenity-maven-plugin</artifactId>
      <version>2.0.81</version>
      <executions>
        <execution>
          <id>serenity-aggregate-reports</id>
          <phase>post-integration-test</phase>
          <goals>
            <goal>aggregate</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

另外,子模块的插件配置只需要保留verify目标(用来生成自身报告)即可,不需要配置aggregate,避免重复执行引发冲突。

3. 确认子模块Feature文件的规范

Screenplay模式下,Serenity识别Requirements/Features/Stories依赖于Feature文件的位置和声明规范:

  • 确保每个子模块的Feature文件都放在src/test/resources/features目录下
  • Feature文件开头要明确声明Feature信息,比如:
    Feature: Demo One User Account Management
      As a registered user
      I want to manage my account settings
    
      Scenario: Update user profile successfully
        Given I am on the profile settings page
        When I update my personal information
        Then the profile should display the updated details
    

如果子模块的Feature文件没有正确声明Feature/Story信息,聚合时可能无法被识别。

4. 彻底清理后重新执行

残留的旧报告文件可能导致聚合异常,执行以下命令彻底清理后重新运行:

mvn clean verify serenity:aggregate

先清空所有模块的target目录,再执行测试生成各自报告,最后执行聚合任务。

验证方式

执行完成后,打开父模块target/site/serenity/index.html,切换到Requirements标签页,就能看到所有子模块的Feature和Story数据了。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.14 08:16:28