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

使用Cucumber ExtentReports遇测试名称非空校验错误求助

解决Cucumber ExtentReports的"Test name must not be null or empty"错误

错误原因

该错误是由于ExtentReports在创建测试节点时,获取到的测试名称(如Scenario Outline或Scenario的名称)为空或null,触发了非空断言校验失败。

解决方案

1. 检查Feature文件的测试定义

  • 确保所有Scenario和Scenario Outline都有明确的名称,不能留空。示例:
    # 错误写法:无名称
    Scenario Outline:
      Given 用户输入账号密码
    
    # 正确写法:带明确名称
    Scenario Outline: 验证多场景用户登录
      Given 用户输入账号<username>和密码<password>
    
  • 排查是否存在误写的空白测试定义,比如Scenario:后未输入名称的情况。

2. 补充Cucumber-ExtentReports适配器依赖

你当前仅添加了核心extentreports依赖,但缺少Cucumber与ExtentReports集成的适配器,这会导致无法正确解析Cucumber测试元数据。需在pom.xml中添加对应适配器依赖:

<dependency>
    <groupId>com.aventstack</groupId>
    <artifactId>extentreports-cucumber5-adapter</artifactId>
    <version>5.0.9</version>
</dependency>

注意:适配器版本需与extentreports版本保持一致(此处均为5.0.9);若使用Cucumber 6+版本,需替换为extentreports-cucumber6-adapter,以此类推匹配对应Cucumber版本。

3. 验证测试运行配置

  • 确保Cucumber运行配置中指定了ExtentReports适配器监听器:
    @CucumberOptions(
        plugin = {"com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:"},
        features = "src/test/resources/features",
        glue = "stepDefinitions"
    )
    
  • 检查自定义钩子或监听器代码,确认未修改测试名称获取逻辑导致返回null。

4. 清理并重新构建项目

执行mvn clean install清理依赖缓存,确保新添加的适配器依赖被正确加载。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.15 02:12:16