I have a spring boot application, it has a couple of @Entity and @RepositoryRestResource repositort classes for them. Now I want to write some tests where I can verify that I can add a new record to my database using these repositories, but I do not want to use my customized MySQL database for it, but instead I want to use some built-in db like H2 . At the moment, I have an application.properties file that looks like this:
spring.jpa.hibernate.ddl-auto=create spring.datasource.url=jdbc:mysql:
Question: How to configure the application to use other db for tests? I do not have xml in my project, everything is based on annotations. I tried to define the @Configuration class with @Bean to create a DataSource , and then use it with the @ContextConfiguration annotation in the test class, but it says that it cannot load the context.
source share