Cucumber 7本地生成HTML报告方法求助
Cucumber 7 本地生成HTML报告解决方案
核心问题说明
你当前使用Cucumber 7 + JUnit 5平台引擎,现有教程多基于旧版弃用的@CucumberOptions注解,且缺少HTML报告必备依赖,导致无法生成本地报告。以下是适配Cucumber 7的实操方案:
步骤1:添加HTML报告依赖
在POM.xml的<dependencies>节点中加入Cucumber HTML报告依赖(因已导入Cucumber BOM,无需指定版本):
<dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-html</artifactId> <scope>test</scope> </dependency>
步骤2:配置本地报告插件路径
修改RunCucumberTest.java中的插件配置,添加HTML报告的输出路径:
import org.junit.platform.suite.api.*; import static io.cucumber.junit.platform.engine.Constants.*; @Suite @IncludeEngines("cucumber") @SelectClasspathResource("thirdpartytest") @ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "pretty, html:target/cucumber-reports.html") public class RunCucumberTest { }
pretty:保持控制台格式化输出测试结果html:target/cucumber-reports.html:指定在项目target目录下生成名为cucumber-reports.html的本地报告
步骤3:生成并查看报告
运行RunCucumberTest类,或执行Maven命令:
mvn test
测试完成后,在项目根目录的target文件夹中找到cucumber-reports.html,用浏览器打开即可查看完整HTML报告。
关于在线报告推送的补充(可选)
若后续需要推送报告至在线平台,需确保网络可正常访问目标地址,并在src/test/resources/junit-platform.properties中添加:
cucumber.publish.enabled=true cucumber.publish.token=你的账户令牌(可选,用于关联报告)
内容的提问来源于stack exchange,提问作者Chetan Krishna
相关产品推荐
相关产品推荐

