jeudi 19 novembre 2015

spring boot integrated tests on multiple databases using TestSuite and different properties files

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:

  • for test suite 1, integration tests, run the tests of all those classes first using a derby properties file and then with an oracle properties file
  • test suite 2, typical unit tests, just use derby

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.

Aucun commentaire:

Enregistrer un commentaire