【发布时间】:2019-08-04 04:38:34
【问题描述】:
我想在不涉及我的主要 Spring 配置的情况下为我的 DAO 层运行 JUnit 测试。因此,我声明了一个带有 @Configuration 注释的内部类,以便它覆盖带有 @SpringBootApplication 注释的主应用程序类的配置。
这是代码:
@RunWith(SpringRunner.class)
@JdbcTest
public class InterviewInformationControllerTest {
@Configuration
class TestConfiguration{
@Bean
public InterviewInformationDao getInterviewInformationDao(){
return new InterviewInformationDaoImpl();
}
}
@Autowired
private InterviewInformationDao dao;
@Test
public void testCustomer() {
List<Customer> customers = dao.getCustomers();
assertNotNull(customers);
assertTrue(customers.size() == 4);
}
}
但我得到了错误:
Parameter 0 of constructor in com.test.home.controller.InterviewInformationControllerTest$TestConfiguration required a bean of type 'com.test.home.controller.InterviewInformationControllerTest' that could not be found.
【问题讨论】:
标签: java spring spring-boot junit spring-boot-test