I have a SpringBoot Application and I a config package with
@Configuration
@EnableJpaAuditing
public class PersistenceConfig {
}
But the PersistenceConfig does not get picked up in a PersonRepositoryTest
@RunWith( SpringRunner.class )
@DataJpaTest
public class PersonRepositoryTest {
// Tests ...
}
However, if I change from @DataJpaTest to @SpringBootTest
, PersonRepositoryTest will pick up the config.
My package structure is
- main
- java
- config
PersistenceConfig.java
- domain
Person.java
- persistence
PersonRepository.java
Application.java // @SpringBootApplication
- test
- java
- persistence
PersonRepositoryTest.java
The Testing improvements in Spring Boot 1.4 suggest to test the persistence layer with @DataJpaTest
Observation: Doing both annotations on the Test class still do not import the config @SpringBootTest @DataJpaTest
Question 1: When testing the Persistence Layer with @DataJpaTest how do I properly (best practise way in Spring Boot) import the config package into my Tests?
Question 2: Can it be an acceptable work around using @SpringBootTest? I am aware that @DataJpaTest is also a meta annotation with sensible auto configuration for my database including transaction management. But what If I do not need it?