簡體   English   中英

spring boot test加載在java / resources而不是test / resources中定義的schema.sql

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM