[英]mvn spring-boot:run will not execute schema.sql in resources
[英]spring boot test loads schema.sql defined in java/resources instead of test/resources
我有以下測試:
@RunWith(SpringRunner.class)
@ContextConfiguration
@SpringBootTest(classes = {AccountsServerTest.class, PostgresSQLTestDbConfig.class})
@ActiveProfiles("test")
public class NodeRepositoryTest {
......
}
並且我在src/main/resources
下有schema.sql和data.sql腳本,應該在應用程序啟動時運行。
我還在src/test/resources/
下有另外兩個sql文件,我想在NodeRepositoryTest啟動時運行它們。
但是,出於某種原因,當我啟動NodeRepositoryTest時,會執行src/main/resources
中的腳本。
也許,之前有人遇到過同樣的問題?
我真的很感激任何幫助,
謝謝
您可以手動定義應該應用於測試方法/測試類的.sql
腳本。
請查看官方文檔( https://docs.spring.io/spring/docs/current/spring-framework-reference/testing.html )中的以下示例:
@Test
@Sql({"/test-schema.sql", "/test-user-data.sql"})
public void userTest {
// execute code that relies on the test data
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.