I'm testing my JPA repositories using @DataJpaTest
with Liquibase (@DataJpaTest
+ H2 + Liquibase) and I've noticed that Spring runs Liquibase migration scripts for each @DataJpaTest
class which is time consuming. Is there a way to run migration scripts once to prepare in-memory database schema for all the tests?
Datasource details are in single application-test.yml
file.
spring:
test:
database:
replace: none
datasource:
driver-class-name: org.h2.Driver
url: jdbc:h2:mem:test;MODE=MYSQL;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS testschema
username: test
password:
liquibase:
enabled: true
change-log: changelog.yml
All the test classes are initialized as below
@ActiveProfiles("test")
@DataJpaTest
class RepositoryTest {
}