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

Azure自托管代理上JUnit5+Cucumber7并行测试发现失败求助

解决Azure自托管代理上JUnit5+Cucumber7并行测试发现失败问题

问题背景

本地通过@Suite注解和junit-platform.properties配置已实现JUnit5+Cucumber7测试场景的并行执行,但在Azure自托管代理上运行Maven任务时,出现Cucumber测试引擎无法发现测试的错误,构建失败。相关依赖版本如下:

<cucumber.version>7.6.0</cucumber.version>
<junit.jupiter.version>5.9.2</junit.jupiter.version>
<maven.surefire.plugin.version>3.0.0-M5</maven.surefire.plugin.version>
<maven.compiler.source.version>11</maven.compiler.source.version>
<maven.compiler.target.version>11</maven.compiler.target.version>
<!-- 其他依赖省略 -->

核心报错信息:

WARNING: Discovering tests using the cucumber.features property. Other discovery selectors are ignored!
[ERROR] TestEngine with ID 'cucumber' failed to discover tests

解决方案

1. 统一Maven Surefire插件版本

报错日志显示实际使用的是3.0.0-M7版本,但POM配置的是3.0.0-M5,版本不一致会引发兼容性问题。建议升级到稳定适配版(如3.1.2),并明确配置并行参数:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.1.2</version>
    <configuration>
        <parallel>methods</parallel>
        <threadCount>4</threadCount>
        <properties>
            <configurationParameters>
                cucumber.execution.parallel.enabled=true
                cucumber.execution.parallel.config.strategy=fixed
                cucumber.execution.parallel.config.fixed.parallelism=4
            </configurationParameters>
        </properties>
    </configuration>
</plugin>

2. 移除冲突的cucumber.features配置

警告信息表明当前通过cucumber.features属性发现测试,导致@Suite注解的发现逻辑被忽略。需:

  • 删除junit-platform.properties中的cucumber.features=xxx配置项
  • 确保测试入口类(如RunCucumberTest)的注解配置正确:
import org.junit.platform.suite.api.ConfigurationParameter;
import org.junit.platform.suite.api.IncludeEngines;
import org.junit.platform.suite.api.SelectPackages;
import org.junit.platform.suite.api.Suite;

import static io.cucumber.junit.platform.engine.Constants.PLUGIN_PROPERTY_NAME;

@Suite
@IncludeEngines("cucumber")
@SelectPackages("com.your.test.package") // 替换为你的Cucumber测试包路径
@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "pretty, html:target/cucumber-report.html")
public class RunCucumberTest {
}

3. 确保测试资源路径匹配

Azure代理的工作目录结构可能与本地不同,需验证:

  • Feature文件放置在src/test/resources下的对应包路径中(如测试类在com.your.test.package,则Feature文件在src/test/resources/com/your/test/package)
  • Maven资源插件配置正常,确保构建时复制resources目录:
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <version>3.3.1</version>
</plugin>

4. 统一并行配置逻辑

避免junit-platform.properties与Surefire插件的并行配置冲突,推荐在Surefire插件中集中配置并行参数,junit-platform.properties仅保留必要项:

cucumber.plugin=pretty, html:target/cucumber-report.html
cucumber.glue=com.your.test.package

验证步骤

  1. 在Azure代理上执行mvn clean test -X,查看详细日志确认Cucumber是否扫描到Feature文件
  2. 检查target/surefire-reports下的报告,确认测试是否被正常发现
  3. 确认代理上的JDK版本为11,与POM中source/target版本一致

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.27 12:45:01