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

如何通过Karate生成Cucumber JSON格式测试报告?

生成Cucumber JSON格式报告的配置方案

关键配置调整

  • 在Runner类的@CucumberOptions注解中,必须明确指定JSON报告的输出路径,示例代码如下:
@RunWith(Cucumber.class)
@CucumberOptions(
    features = "src/test/resources/features",
    glue = "com.yourpackage.stepdefinitions",
    plugin = {
        "json:target/cucumber-reports/cucumber.json", // 核心配置:指定JSON报告生成路径
        "html:target/cucumber-reports/cucumber.html"
    }
)
public class TestRunner {
}
  • 验证依赖版本一致性,确保Cucumber相关依赖版本统一,以Maven为例:
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-java</artifactId>
    <version>7.14.0</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-junit</artifactId>
    <version>7.14.0</version>
    <scope>test</scope>
</dependency>

排查要点

  • 检查target/cucumber-reports目录是否有读写权限,执行测试后查看该路径下是否生成cucumber.json文件
  • 使用构建工具执行测试时,避免添加跳过报告生成的参数,比如Maven直接执行mvn test
  • 确认没有自定义的报告拦截逻辑覆盖或阻止Cucumber JSON报告的生成

内容的提问来源于stack exchange,提问作者NAYELYS IBAÑEZ

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.08 14:40:34