【发布时间】:2019-08-04 06:10:12
【问题描述】:
我不想加载整个 Spring Boot 配置来对我的DAO 层进行单元测试,因此创建了一个嵌套配置类来抑制默认配置。但是当我尝试指定 SQL 脚本让它在测试之前运行时,它无法找到它们。
代码如下:
package com.test.customer.controller;
..
@RunWith(SpringRunner.class)
@JdbcTest
@Sql({"data.sql"})
public class InterviewInformationControllerTest {
@Configuration
static class TestConfiguration{
}
@Test
public void testCustomer() {
// code
}
}
I get the error: Cannot read SQL script from class path resource [com/test/customer/controller/data.sql]; nested exception is java.io.FileNotFoundException: class path resource [com/test/customer/controller/data.sql] cannot be opened because it does not exist
我尝试将文件放在src/main/resources(不是首选)和src/test/resources(我更喜欢)
注意:我在 Eclipse 中通过 Run as -> JUnit test 运行单元测试。
编辑:在配置类中添加static关键字
【问题讨论】:
标签: java spring spring-boot junit spring-boot-test