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

不使用测试运行器如何生成Cucumber测试报告

问题解答

完全可以,io.cucumber.core.cli.Main原生支持Cucumber所有官方内置插件,pretty插件也在支持范围内,无需额外适配。

你只需要在调用Main.run()方法传入的启动参数中,添加--plugin pretty配置即可启用该插件:

  • 仅配置--plugin pretty时,pretty格式的测试结果会直接输出到控制台
  • 需要把报告持久化为文件时,可以指定输出路径,格式为--plugin pretty:${报告文件路径},示例:--plugin pretty:target/cucumber-pretty-report.txt

调用代码示例

// 配置Cucumber启动参数
String[] cucumberArgs = new String[]{
    // 指定step定义所在的包路径
    "--glue", "com.your.project.step",
    // 启用pretty插件,同时输出到控制台和本地文件
    "--plugin", "pretty",
    "--plugin", "pretty:target/cucumber-pretty-report.txt",
    // 可选:同时启用其他插件,比如json报告
    "--plugin", "json:target/cucumber.json",
    // 指定feature文件所在路径
    "src/test/resources/features"
};

// 执行测试,返回值为测试执行的退出码
int exitCode = io.cucumber.core.cli.Main.run(cucumberArgs, Thread.currentThread().getContextClassLoader());

注意事项

  • pretty插件是Cucumber核心内置功能,只要你项目中已经引入对应版本的cucumber-core依赖即可使用,不需要额外引入其他依赖包
  • 不要重复声明pretty插件配置,否则会出现结果重复打印/重复生成文件的问题
  • 如果你需要调整pretty报告的输出格式,可以配合--monochrome参数关闭控制台彩色输出,适配纯文本文件的存储需求

内容的提问来源于stack exchange,提问作者jactor-rises

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.04 23:24:01