这篇文章是对前面part1、part2相关常见报错及其解决方法
1. 关于CucumberException之@Autowired未生效的问题
报错详情
如果你报了如上图的异常,不要着急去百度,我们往下看,找到下面的Caused by…
此时你会发现,报错的真实原因其实是NoSuchBeanDefinitionException即我们代码中的@Autowired未生效
解决方法
在测试启动类上添加@SpringBootTest注解
package com.aqin;
import io.cucumber.spring.CucumberContextConfiguration;
import org.junit.platform.suite.api.ConfigurationParameter;
import org.junit.platform.suite.api.IncludeEngines;
import org.junit.platform.suite.api.SelectClasspathResource;
import org.junit.platform.suite.api.Suite;
import org.springframework.boot.test.context.SpringBootTest;
import static io.cucumber.junit.platform.engine.Constants.PLUGIN_PROPERTY_NAME;
import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME;
@Suite
@SpringBootTest
@CucumberContextConfiguration
@IncludeEngines("cucumber")
@SelectClasspathResource("com/aqin")
@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "pretty")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "com.aqin")
public class RunCucumberTest {
}
2. 关于IllegalStateException之ClassNotFoundException的问题
报错详情
看到如上图的异常,同样我们需要先找到最下面的Caused by…
报错的真实原因其实是JdbcTransactionManager的支持问题,即pom文件中中的org.springframework.jdbc的版本问题。
解决方法
更新依赖版本
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.3.4</version>
</dependency>
3. No features found at classpath:/
报错详情
明明写了Feature,而且配置也都按教程修改了,但是执行时却显示没有feature(哭唧唧…)
先别哭,如果你用的是idea,可能只是多勾选了个东西
解决方法
打开idea的Preference
按照下图1、2、3、4,如果你4处勾选了,取消就可以
如果本来就没选,看下你的JDK选的对不对,主要查看两个地方
1. 编译器
1⃣️ 选择1.8版本
2. 项目结构
1⃣️ 选择本地安装的1.8版本JDK
2⃣️ 选择SDK 8
如果JDK也没问题(呃…问度娘吧孩纸…)
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/135432.html