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

Jenkins中Cucumber测试重复执行及指定Runner文件运行咨询

只在Jenkins中运行特定Cucumber Runner文件的解决方案

Absolutely! You can definitely run only specific Cucumber runner files in Jenkins instead of having all tests execute twice. Here's how to configure it properly:

1. 核心原理:利用Maven Surefire插件指定测试类

Cucumber runner classes are essentially JUnit test classes (annotated with @RunWith(Cucumber.class)), so we can use Maven's Surefire plugin to target exactly the runners we want to execute.

2. 在Jenkins的「Goal and options」中配置命令

In your Jenkins job configuration, navigate to the Build section (for Maven projects, it's the "Goals and options" field). Use the following syntax to specify your target runner(s):

运行单个特定Runner

Use the test goal with the -Dtest parameter, providing the full qualified class name (package + class name) of your runner:

clean test -Dtest=com.yourpackage.runner.YourTargetRunner

Example: If your runner is in com.ecommerce.runner and named CheckoutFlowRunner, the command would be:

clean test -Dtest=com.ecommerce.runner.CheckoutFlowRunner

运行多个特定Runners

Separate multiple runner class names with commas (still use full qualified names if they're in different packages):

clean test -Dtest=com.ecommerce.runner.LoginRunner,com.ecommerce.runner.CheckoutFlowRunner

If all your runners are in the same package, you can even use wildcard patterns (though explicit names are safer to avoid unintended runs):

clean test -Dtest=com.ecommerce.runner.*Runner

3. 解决「全部测试执行两次」的问题

The double execution issue usually stems from one of these scenarios:

  • Your Jenkins job has duplicate build steps that trigger the test phase
  • Your pom.xml has conflicting configurations (e.g., both Surefire and Failsafe plugins configured to run tests, or the same plugin executing twice)
  • You're using a default Maven command like clean install which might trigger tests in multiple phases

To fix this:

  • Check your Jenkins job's build steps to ensure only one Maven command is running tests
  • Review your pom.xml to confirm only the Surefire plugin is configured to execute your Cucumber runners, with no duplicate executions

注意事项

  • Make sure your runner classes are properly annotated with @RunWith(Cucumber.class) so the Surefire plugin recognizes them as test classes
  • Class names are case-sensitive, so double-check the spelling and capitalization
  • If you omit the package name, ensure the plugin's testClassesDirectory or includes configuration in pom.xml covers the correct package

内容的提问来源于stack exchange,提问作者K.Krishnakanth

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 03:24:10