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

Cucumber 7.14.0中如何在Cucumber Options中使用多标签?

解决Cucumber 7.14.0多标签使用报错问题

问题原因

Cucumber 7.x版本对@CucumberOptions的tags参数做了调整,不再支持数组形式({}包裹的写法),该参数现在仅接受单个字符串类型的值,这直接导致你遇到Type mismatch: cannot convert from String[] to String的类型转换错误。

修正后的代码

将tags的数组写法改为单个字符串,多个标签通过逻辑运算符连接:

  • 要运行任意一个标签的用例(逻辑或),用or或直接空格分隔
  • 要运行同时满足多个标签的用例(逻辑与),用and连接
package com.app.main;

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

@RunWith(Cucumber.class)
@CucumberOptions(
        glue = {"com.app.stepdef"},
        features = {"Features"},
        plugin = {"pretty","html:target/HtmlReport.html","json:target/JSONReport.json"},
        dryRun = true,
        monochrome=true,
        tags = "@smoke or @sanity" // 运行带@smoke或@sanity标签的用例
        // 若需同时满足两个标签,可写为 tags = "@smoke and @sanity"
)
public class MyRunner {
}

额外说明

  • 排除指定标签的用例可使用not,比如@smoke not @ignore
  • 空格分隔多个标签等价于or逻辑,即@smoke @sanity和@smoke or @sanity效果一致

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.04 01:43:20