I am developing a micro-service application using Spring Boot. My application will use for production configuration a Postgres DB and for Spring Boot auto-test a H2 DB. My pom.xml includes therefore both dependencies (H2 + Postgres). I tried to associate H2 dependency with tes scope, and Postgres with runtime as following:
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>test</scope>
</dependency>
I can see when running mvn test that Spring Boot selects by default postgres database which is not present within my unit test environment. This is the reason why I prefer using H2 for running unit tests.
Is there a proper way to tell spring boot to use H2 for test and Postgres otherwise?
I don't know if using different application.properties file (one in src/main/resources and the other in src/test/resources) would solve the issue.