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

Maven集成Cucumber测试报告生成:JSON文件未找到问题排查

Spring Boot + Cucumber 集成测试报告生成异常排查

我给Spring Boot应用搭了Cucumber集成测试套件,执行mvn clean verify时测试能正常运行,HTML报告也能生成,但总是弹出No JSON report file was found错误。调整过好几次路径都没解决,麻烦帮忙排查下。

文件夹结构

|_ src
  |_ main
  |_ test
    |_ java
      |_ common
      |_ steps
      |_ CucumberIntegrationRunnerTest.java
    |_ resources
      |_ data
        |_ [json files]
      |_ [feature files]
  |_ target

pom.xml 关键配置

<dependencies>
    <!-- cucumber for integration tests-->
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>7.18.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>7.18.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-spring</artifactId>
        <version>7.18.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>net.masterthought</groupId>
        <artifactId>maven-cucumber-reporting</artifactId>
        <version>5.8.1</version>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-junit-platform-engine</artifactId>
        <version>7.18.0</version>
        <scope>test</scope>
    </dependency>
</dependencies>
<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
            <testFailureIgnore>true</testFailureIgnore>
            <includes>
                <include>**/*Test.java</include>
            </includes>
        </configuration>
    </plugin>
    <plugin>
        <groupId>net.masterthought</groupId>
        <artifactId>maven-cucumber-reporting</artifactId>
        <version>5.8.1</version>
        <executions>
            <execution>
                <id>execution</id>
                <phase>verify</phase>
                <goals>
                    <goal>generate</goal>
                </goals>
                <configuration>
                    <projectName>optumcare-individual-azure-sink</projectName>
                    <outputDirectory>${project.build.directory}</outputDirectory>
                    <cucumberOutput>${project.build.directory}/cucumber.json</cucumberOutput>
                    <checkBuildResult>false</checkBuildResult>
                    <jsonFiles>
                        <param>**/cucumber.json</param>
                    </jsonFiles>
                    <buildNumber>1</buildNumber>
                    <checkBuildResult>false</checkBuildResult>
                </configuration>
            </execution>
        </executions>
    </plugin>
</plugins>

测试运行类代码

@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("cucumber/integration")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "path_to_integration_folder")
@CucumberOptions(plugin = {"pretty", "json:target/cucumber.json"}, monochrome = true)
@CucumberContextConfiguration
@SpringBootTest
public class CucumberIntegrationRunnerTest { ... }

问题排查与修复方案

1. 移除冲突的报告配置参数

maven-cucumber-reporting插件中cucumberOutput和jsonFiles参数存在优先级冲突,建议只保留jsonFiles并明确指定路径:

<configuration>
    <!-- 移除 cucumberOutput 配置项 -->
    <jsonFiles>
        <param>${project.build.directory}/cucumber.json</param>
    </jsonFiles>
    <!-- 其他原有配置保留 -->
</configuration>

2. 修正JUnit Platform模式下的报告配置

Cucumber 7.x版本中,使用@Suite+JUnit Platform Engine时,@CucumberOptions的插件配置可能不生效,需改用@ConfigurationParameter指定报告插件:

@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("cucumber/integration")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "path_to_integration_folder")
@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "pretty,json:target/cucumber.json")
@CucumberContextConfiguration
@SpringBootTest
public class CucumberIntegrationRunnerTest { ... }

3. 验证JSON报告生成时机

执行mvn clean test后,检查target目录下是否存在cucumber.json:

  • 如果不存在,说明测试执行阶段未生成JSON报告,需重点排查测试运行类的插件配置是否生效;
  • 如果存在,说明报告生成顺序或路径匹配存在问题,可尝试在maven-cucumber-reporting配置中添加strictValidation=false参数。

4. 匹配插件兼容版本

当前Cucumber版本为7.18.0,maven-cucumber-reporting5.8.1版本兼容性不足,建议升级到适配Cucumber 7.x的最新版本:

<dependency>
    <groupId>net.masterthought</groupId>
    <artifactId>maven-cucumber-reporting</artifactId>
    <version>5.12.0</version>
    <scope>test</scope>
</dependency>

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.20 06:27:04