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

如何在Karate中按指定标签值运行场景及执行配置

Karate按标签值运行测试场景的方法

命令行方式

Karate支持直接通过@标签名=值的格式筛选带特定值的标签场景,结合karate.options的--tags参数即可执行:

  • 运行标签two值为foo的场景:

    mvn test -Pkarate -Dkarate.options="--tags @two=foo"
    

    该命令会匹配并执行示例中的第二个场景。

  • 运行标签two值为bar的场景:

    mvn test -Pkarate -Dkarate.options="--tags @two=bar"
    

    该命令会匹配并执行示例中的第三个场景。

  • 运行标签two值为foo,bar的场景:

    mvn test -Pkarate -Dkarate.options="--tags @two=foo,bar"
    

    该命令会匹配并执行示例中的第一个场景。

  • 同时运行标签two值为foo和bar的场景(逻辑或):

    mvn test -Pkarate -Dkarate.options="--tags @two=foo,@two=bar"
    

    该命令会执行示例中的第二、第三个场景。

Java代码方式

在Java执行器中,直接在tags()方法参数里传入@标签名=值的格式即可实现按标签值筛选:

  • 运行标签two值为foo的场景:

    Results results = Runner.path("classpath:karate/features")
        .tags("@two=foo")
        .parallel(5);
    
  • 同时运行标签two值为foo和bar的场景:

    Results results = Runner.path("classpath:karate/features")
        .tags("@two=foo,@two=bar")
        .parallel(5);
    
  • 排除标签two值为bar的场景:

    Results results = Runner.path("classpath:karate/features")
        .tags("~@two=bar")
        .parallel(5);
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.04 04:20:10