簡體   English   中英

Spring Boot測試總是運行模式 - $ {platform} .sql

[英]Spring Boot tests always running schema-${platform}.sql

當我在Spring Boot上運行測試時,兩個schema-${platform}.sqldata-${platform}.sql正在運行。

在我的場景中,我必須從測試中刪除schema.sql並設置datasource屬性datasource.jpa.hibernate.ddl-auto=update 當我從測試文件夾中刪除'Schema 2'時'Schema 1'繼續運行。

我有以下目錄結構:

├───src
│   ├───main
│   │   └───resources
│   │       ├───locale
│   │       └───static
│   │       └data-mysql.sql
│   │       └schema-mysql.sql //Schema 1
│   └───test
│       └───resources
│          └data-mysql.sql
│          └schema-mysql.sql //Schema 2

- > Schema 1Schema 2都有相同的sql指令。

無論如何要將data-mysql.sql在tests文件夾中,從test文件夾中刪除schema-mysql.sql並且測試不運行' Schema 1 '?

一種解決方案是使用不同的配置文件進行測試

1.因此,對於測試,您將在JVM命令行上設置系統屬性。 例如-Dspring.profiles.active = testing -Dspring.profiles.active = ci或者像-Dspring.profiles.active = raining一樣隨機的東西

2.然后,您將創建與該配置文件匹配的第二個application.properties文件

例如application-testing.properties

然后,在該屬性文件中,您可以使用指定has數據文件的位置和名稱

spring.datasource.schema =

Spring Boot配置文件
https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html


https://www.mkyong.com/spring-boot/spring-boot-profiles-example/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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