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

Maven构建在Cucumber场景失败时未终止问题求助

Cucumber场景失败时终止Maven构建的配置方案

以下是几个关键配置点,你可以逐一排查:

  • 配置maven-surefire-plugin
    在pom.xml的build/plugins节点下添加或修改该插件配置,确保测试失败时不会忽略错误:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>3.2.5</version>
        <configuration>
            <testFailureIgnore>false</testFailureIgnore>
            <includes>
                <include>**/RunCucumberTest.java</include>
            </includes>
        </configuration>
    </plugin>
    

    testFailureIgnore设为false是核心(默认值也是false,但可能被其他配置覆盖),同时要指定你的Cucumber测试运行类,确保插件能识别并执行测试。

  • 检查Cucumber运行器的strict模式
    打开你的Cucumber测试运行类(比如RunCucumberTest),在@CucumberOptions里确认strict=true,这个配置会让场景失败时抛出异常,让Maven捕获并终止构建:

    @CucumberOptions(
        features = "src/test/resources/features",
        glue = "com.example.stepdefinitions",
        strict = true
    )
    public class RunCucumberTest extends AbstractTestNGCucumberTests {
    }
    
  • 注意maven-failsafe-plugin的配置(如果用它跑集成测试)
    如果你用failsafe插件执行集成测试,同样要在插件配置里设置testFailureIgnore=false,并且执行./mvnw verify命令触发测试阶段。

  • 确认Maven执行命令
    确保你执行的是./mvnw test或./mvnw verify这类包含测试阶段的命令,仅执行compile或package不会触发测试失败后的构建终止。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.12 15:42:09