API自动化项目集成Extent Reports遇类缺失错误求助
问题描述
尝试在API自动化项目中集成Extent Reports,已添加如下相关依赖:
<dependency> <groupId>io.rest-assured</groupId> <artifactId>rest-assured</artifactId> <version>4.3.3</version> <scope>test</scope> </dependency> <dependency> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-picocontainer</artifactId> <version>5.7.0</version> <scope>test</scope> </dependency> <dependency> <groupId>io.rest-assured</groupId> <artifactId>json-path</artifactId> <version>4.3.3</version> <scope>test</scope> </dependency> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-core</artifactId> <version>5.7.0</version> <scope>test</scope> </dependency> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-java</artifactId> <version>5.7.0</version> <scope>test</scope> </dependency> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-junit</artifactId> <version>5.7.0</version> <scope>test</scope> </dependency> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-junit-platform-engine</artifactId> <version>5.7.0</version> <scope>test</scope> </dependency> <!-- Extent Report --> <dependency> <groupId>com.aventstack</groupId> <artifactId>extentreports</artifactId> <version>4.1.7</version> </dependency> <!-- Cucumber ExtentReport Adapter --> <dependency> <groupId>tech.grasshopper</groupId> <artifactId>extentreports-cucumber5-adapter</artifactId> <version>2.13.0</version> </dependency>
同时在Cucumber Runner类中添加了插件配置:
plugin = {"com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:"}
运行脚本时出现错误:
io.cucumber.core.exception.CucumberException: java.lang.NoClassDefFoundError: com/aventstack/extentreports/reporter/ReporterConfigurable
注:使用info.cukes cucumber和vimalselvam extent report时可正常运行。
解决方案
原因分析
ReporterConfigurable是Extent Reports 5.x版本新增的接口,你当前使用的Extent Reports版本为4.1.7,而extentreports-cucumber5-adapter:2.13.0依赖的是更高版本的Extent Reports,版本不匹配导致找不到该类。
修复步骤
- 升级Extent Reports版本
将Extent Reports依赖版本调整为与适配器兼容的5.x稳定版本(比如5.0.9):
<!-- Extent Report --> <dependency> <groupId>com.aventstack</groupId> <artifactId>extentreports</artifactId> <version>5.0.9</version> <scope>test</scope> </dependency>
- 修正Runner类的插件路径
使用tech.grasshopper适配器对应的正确插件类,而非com.aventstack的路径:
plugin = {"tech.grasshopper.extentreports.cucumber.adapter.ExtentCucumberAdapter:"}
- 可选:添加Spark Reporter依赖
若需要生成可视化HTML报告,可补充适配Extent Reports 5.x的Spark Reporter依赖:
<dependency> <groupId>com.aventstack</groupId> <artifactId>extentreports-spark-reporter</artifactId> <version>5.0.9</version> <scope>test</scope> </dependency>
验证
清理Maven/Gradle依赖缓存,重新构建项目后运行测试,错误即可消除,Extent Reports会正常生成报告。
内容的提问来源于stack exchange,提问作者Karunagara
相关产品推荐
相关产品推荐

