As per the DataJpaTest documentation tests annotated with @DataJpaTest
will by default use embedded in-memory database(h2)
By default, tests annotated with @DataJpaTest are transactional and roll back at the end of each test. They also use an embedded in-memory database (replacing any explicit or usually auto-configured DataSource). The @AutoConfigureTestDatabase annotation can be used to override these settings.
But in my case it is not happening, Test class annotated with @DataJpaTest
is loading the postgres dialect instead of using h2 dialect.
Below is the property file from main/resources
spring:
datasource:
url: jdbc:postgresql://localhost:5432/postgres?currentSchema=test
username: test
password: test
jpa:
database-platform: org.hibernate.dialect.PostgreSQLDialect