This repository contains all the code examples from the Testing Spring Data JPA Repositories tutorial.
Read the complete tutorial with detailed explanations here:
https://www.javapro.academy/testing-spring-data-jpa-repositories/
This repository includes working Java examples demonstrating:
- Setting up repository tests with
@DataJpaTest - Using
TestEntityManagerto insert test data independently - Testing derived query methods (e.g.,
findByDepartment) - Testing comparison queries with boundary conditions
- Testing custom
@QueryJPQL methods with ordering - Testing projection interfaces and DTO queries
- Why
TestEntityManageris preferred over the repository for test setup
- Java 17 or higher
- Maven (for dependency management)
- Spring Boot 3.x
Clone the repository:
git clone <your-repo-url>
cd testing-spring-data-jpa-repositoriesInstall dependencies:
mvn clean installRun the tests:
mvn testOr run the test class directly from your IDE (IntelliJ IDEA, Eclipse, VS Code).
The project uses the following key dependencies:
- Spring Boot Starter Data JPA – JPA and Hibernate support
- Spring Boot Starter Test – JUnit 5, AssertJ, and test utilities
- H2 Database – In-memory database for testing
Visit JavaPro Academy for more Java tutorials and courses:
https://www.javapro.academy/
Last Updated: February 9, 2026