我正在使用spring-boot-test进行一些集成测试(weblayer +数据库)。由于我的域类是@Entity,hibernate将自动生成testdb中的数据库,该数据库是嵌入h2的。
问:在测试中进行hibernate/jpa的初始化之前,如何运行脚本?
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public void MyITest {
@Test
public void test() {
}
}我添加了一个src/test/resources/schema-test.sql,但这在默认情况下似乎不会被选中。尤其是在hibernate自动生成存根之前。
发布于 2018-07-23 13:48:56
我只需要使用src/test/resources/schema.sql
发布于 2018-07-24 06:55:57
您可以使用@Sql并设置脚本的路径
@Test
@Sql({"/test-schema.sql", "/test-user-data.sql"})
public void userTest {
// execute code that relies on the test schema and test data
}全信息弹簧试验数据库
https://stackoverflow.com/questions/51479829
复制相似问题