springspring-bootprofilespring-profilesspring-properties

Springboot database URL change during integration testing


I am doing integration testing, and have 2 databases to test my project against. Rather than creating 2 profiles, is there a quick and easy way where I create 2 integration test classes, and one to test against the database originally written on my main profile, and another where I add some sort of annotation that changes the database url programatically, but otherwise keeps everything else the same, and run my tests through there?

Thanks!


Solution

  • You can add separate properties file in your test resources then on your second integration test class use annotation @PropertySource.

    Have a look at https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/context/annotation/PropertySource.html for details