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

使用Surefire插件重跑Cucumber测试时报告异常问题求助

Surefire重跑Cucumber失败场景时的报告匹配问题

问题背景

我在用Surefire插件重跑失败的Cucumber场景时,遇到了报告显示异常的问题。插件配置如下:

<configuration>
    <rerunFailingTestsCount>2</rerunFailingTestsCount>
</configuration>

首次运行后,测试报告能正常显示场景名称和示例编号,结果如下:

  • Example 1: 失败
  • Example 2: 通过

异常表现

Surefire触发失败测试重跑后,报告里的重跑记录显示为"Example #1" classname="Examples",总运行次数统计为3次(假设重跑通过),而且重跑记录无法和首次的测试记录匹配,也不会被标记为不稳定测试。报告片段如下:

<testcase name="Login - After login session(...) - Example #1" classname="Login - After login session (...) - Examples" time="31.412">
    <failure>(...)</failure>
</testcase>

<testcase name="Login - After login session (...) - Examples - Example #2" classname="Login - After login session (...) - Examples" time="25.591"/>

<testcase name="Example #1" classname="Examples" time="12.615"/>

问题根源排查

我检查了JUnit的TestIdentifier,发现重跑时的类名是Examples,和首次运行时不一致。

首次运行的测试层级结构(基于testIdentifier.getDisplayName()):

Cucumber (engine)
Login
Login - Some login scenario
Login - Some login scenario - Examples
Login - Some login scenario - Examples - Example #1.2

重跑时的层级结构:

Cucumber (engine)
Login
Login - Some login scenario
Examples
Example #1.2

这种层级结构的不一致导致了Surefire报告异常。

使用版本

  • Cucumber: 7.11.1
  • Surefire: 3.0.0-M9
  • JUnit: 5.9.2

需求

有没有无需分析/合并报告的解决方案?我已经试过不同的Cucumber 7和JUnit 5配置组合了。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.30 23:15:59