[英]Spring Boot integration tests cannot reach application.properties file
[英]How to instruct Spring Boot to use application.properties file in test's resources when running tests
對於 Spring 引導應用程序,我有以下項目結構。
問題是,每當我運行測試時,Spring 引導應用程序使用項目根目錄中config
文件夾中的application.properties
,而不是src > test > resources
文件夾中的application.properties
。
因此,作為運行測試時的黑客,我在config
文件夾中打亂了application.properties
的名稱。
我如何告訴 Spring Boot 在運行測試時使用測試位置中的application.properties
而無需觸摸config > application.properties
?
我不想根據我是運行應用程序還是運行測試來繼續重命名文件。
您可以在 src/main/resources 文件夾下創建一個配置文件 ( application-test.properties
),然后在您的測試中使用@TestPropertySource(locations = "classpath:application-test.properties")
使用您的測試配置在 src/main/resources 下創建一個 application-test.properties。
比在你的測試中使用如下
@ActiveProfiles("test")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.