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

升级Serenity至3.9.8后本地JUnit Runner无法生成报告求助

Serenity 3.9.8本地JUnit Runner运行不生成报告的解决办法

我们将Serenity版本从3.3.2升级至3.9.8后,本地通过JUnit Runner运行测试时无法生成Serenity报告,但使用Maven执行测试时,可通过Maven插件正常生成报告。本地使用的Runner代码如下:

@RunWith(CucumberWithSerenity.class)
@CucumberOptions(
    plugin = {"pretty"},
    glue = {"com.vicoland"},
    tags = ("not @ignore and @single"),
    features = "src/test/resources/features"
)
public class RunSingleTest {
}

以下是在IntelliJ IDEA中通过上述Runner本地运行测试时,可解决报告生成问题的额外配置:

  • 补充Serenity Cucumber插件配置
    在@CucumberOptions的plugin参数中添加Serenity专属的Cucumber报告插件,Serenity 3.x版本推荐使用SerenityReporterParallel(支持并行测试),单线程场景也可使用SerenityReporter。修改后的配置如下:

    @CucumberOptions(
        plugin = {"pretty", "io.cucumber.core.plugin.SerenityReporterParallel"},
        glue = {"com.vicoland"},
        tags = ("not @ignore and @single"),
        features = "src/test/resources/features"
    )
    
  • 设置IDEA运行时VM参数
    在IntelliJ IDEA的Run Configuration中,为该JUnit Runner添加VM参数,指定报告输出目录和生成类型:

    1. 打开Run Configurations,找到对应的RunSingleTest配置
    2. 切换到"VM options"栏,粘贴以下参数:
    -Dserenity.outputDirectory=target/site/serenity
    -Dserenity.reporter=all
    
  • 确认依赖完整性
    检查pom.xml中Serenity相关依赖版本统一为3.9.8,且包含核心和Cucumber集成依赖:

    <dependency>
        <groupId>net.serenity-bdd</groupId>
        <artifactId>serenity-core</artifactId>
        <version>3.9.8</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>net.serenity-bdd</groupId>
        <artifactId>serenity-cucumber</artifactId>
        <version>3.9.8</version>
        <scope>test</scope>
    </dependency>
    
  • 手动触发报告生成(可选)
    如果上述配置后仍未自动生成报告,可在测试类中添加@AfterClass方法手动触发报告生成:

    import net.serenitybdd.core.Serenity;
    import org.junit.AfterClass;
    
    @RunWith(CucumberWithSerenity.class)
    @CucumberOptions(/* 原有配置 */)
    public class RunSingleTest {
    
        @AfterClass
        public static void generateSerenityReport() {
            Serenity.generateReports();
        }
    }
    

内容的提问来源于stack exchange,提问作者Vayas Zsolt Marton

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.14 03:05:09