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

升级到Cucumber 5.5.0后io.cucumber.java系列注解失效问题求助

问题根因

你的核心问题是Runner类仍在使用旧版本cucumber.api包下的运行器和配置注解,和步骤定义类使用的新版本io.cucumber包不兼容,导致新版本的注解、步骤定义都无法被识别。

解决方案

按以下步骤修改即可正常运行:

步骤1:补充pom.xml依赖

你当前只引入了cucumber-java,缺少对应版本的JUnit运行器依赖,添加以下依赖:

<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-junit</artifactId>
    <version>5.5.0</version>
</dependency>

步骤2:修改Runner类的导入包和配置

将Runner类中旧的cucumber.api导入全部替换为io.cucumber包下的类,同时调整标签表达式的写法(Cucumber 3.x+版本不再支持~排除标签,改用not关键字,同一条规则的标签也不能直接用逗号写在同一个字符串中)。
修改后的完整Runner类代码如下:

package ggh.vcf.testRunner;

import org.junit.runner.RunWith;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;

@RunWith(Cucumber.class)
@CucumberOptions(
        features="Features", 
        glue={"ggh.vcf.stepDefinitions"}, 
        monochrome=true, 
        tags = "not @SmokeTest and @RegressionTest"
)
public class Runner
{

}

步骤3:校验(可选)

确认你项目中所有Cucumber相关的依赖版本统一为5.5.0,不存在跨版本混用的情况,清理Maven缓存后重新运行即可。修改完成后@BeforeStep、@AfterStep注解和所有步骤定义都可以被正常识别。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.01 17:39:04