1

When I run tests on Spring Boot the both schema-${platform}.sql and data-${platform}.sql is running.

In my scenario I have to remove the schema.sql from tests and set the datasource property datasource.jpa.hibernate.ddl-auto=update. When I remove the 'Schema 2' from test folder the 'Schema 1' keep running.

I have the following directory structure:

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

-> Both Schema 1 and Schema 2 has the same sql instructions.

Is there anyway to keep the data-mysql.sql on tests folder, remove the schema-mysql.sql from test folder and the tests not run the 'Schema 1'?

Pablo Souza
  • 863
  • 2
  • 11
  • 25
  • Related Question: https://stackoverflow.com/questions/35531661/using-env-variable-in-spring-boots-application-properties – Theo Briscoe Jun 13 '17 at 18:20

1 Answers1

0

One solution is to user a different profile for testing

1. So for testing you would set a system property on the JVM command line. Such as -Dspring.profiles.active=testing
-Dspring.profiles.active=ci or something as random as -Dspring.profiles.active=raining

2. You would then create a second application.properties file matching the profile

For example application-testing.properties

In that properties file you can then specify the location and name of the have data file using

spring.datasource.schema=

Spring Boot Profile Documentation
https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html

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

Theo Briscoe
  • 367
  • 2
  • 4
  • 13