Spring Boot offers a convenient way of writing test classes to run Spring Data JPA transactions.
Open the Spring Boot ch09-flux
project and add the following test classes for Spring Data JPA repository transactions.
Perform the following steps in creating test cases for Spring Data JPA repository layer:
- Just like in the previous recipe, add the required Spring Test starter POM dependency in the project's
pom.xml
file. - Inside
src/test/java
, create anorg.packt.spring.boot.test
package and add inside a test class with a new annotation,@DataJpaTest
, inside it:
@RunWith(SpringRunner.class) @DataJpaTest @ContextConfiguration(classes={ HRBootApplication.class, CachingConfig.class, SpringDataConfig.class, WebFluxConfig.class}) @AutoConfigureTestDatabase(replace=Replace.NONE) public class EmployeeRepositoryTest { @Autowired private TestEntityManager entityManager; @Autowired private EmployeeRepository...