Reputation: 1205
So, I'm working on a Spring Rest API using JPA and based on an Oracle database.
I have some integration tests, that use Derby instead (embedded db). There is a different application.properties file in src/test/resource with the derby details to achieve that.
There is no XML in my project and nothing apart from this in terms of configuration. (btw, i'm no Spring champion..)
@Configuration
@PropertySource(value = { "classpath:application.properties"}, ignoreResourceNotFound = true)
@EnableAutoConfiguration
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
What I need is for my integration tests to run on both Derby and oracle (and a third db soon).
What I would like to do is say:
Something that would look like this:
@RunWith(Suite.class)
@TestPropertySource(
locations = "/application_oracle.properties",
locations = "/application_derby.properties"
)
@Suite.SuiteClasses({
//Integration
CustomerApiIntegrationTest.class,
StoreApiIntegrationTest.class
})
public class IntegrationTestsSuite{
}
and
@RunWith(Suite.class)
@TestPropertySource(
locations = "/application_derby.properties"
)
@Suite.SuiteClasses({
SimpleCustomerTest.class,
SimpleStorreTest.class
})
public class OtherTestsSuite{
}
but it doesn't work. This TestPropertySource doesn't seem to have any effect at the testSuite level with one properties file, let alone too.
Thanks in advance.
Upvotes: 1
Views: 898
Reputation: 33111
Your best shot at that is to use @ActiveProfiles
for each test suite and refer to a different profile name. Since the profile is part of the key that the framework uses to cache your context, it will create a separate context for each.
Once you've done that, you can create a application-xyz.properties
in src/test/resources
where xyz
is the name of your profile (derby
, oracle
or whatever name you like).
The @PropertySource
on your app is useless, Spring Boot loads application.properties
from the root of the classpath by default.
Upvotes: 3