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!
CodePudding user response:
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
CodePudding user response:
You can simply use the properties
argument of SpringBootTest
, to override specific properties. For example:
@SpringBootTest(properties = { "spring.datasource.url=URL_TO_TEST_DB", "spring.datasource.username=Test"})
public class TestIT {
//...
}