mardi 30 mai 2017

Spring Boot Exclude DataSource Configuration

I have a small application that when live, makes a database connection, and stores and persists some data.

I'm currently in the midsts of trying to write some tests, and I'm wanting to completely cut off the database part of the application, and just mock it in the tests.

The Datasource is setup with a configuration class.

@Component
@Configuration
public class DataSourceConfiguration {
    @Bean
    public DataSource myDataSource() { ... }
}

and a test boostrap that currently looks similar to

@RunWith(SpringRunner.class)
@EnableAutoConfiguration(exclude = {
    DataSourceAutoConfiguration.class,
    DataSourceTransactionManagerAutoConfiguration.class,
    HibernateJpaAutoConfiguration.class
})
public class MyTest {
}

When running the test, I can see that Spring is trying to instantiate Hibernate, and a connection to the db, I assume because of my config class. How can I stop Spring from doing this?

Aucun commentaire:

Enregistrer un commentaire