Skip to content

Latest commit

 

History

History
64 lines (42 loc) · 1.54 KB

File metadata and controls

64 lines (42 loc) · 1.54 KB

Testing Spring Data JPA Repositories

This repository contains all the code examples from the Testing Spring Data JPA Repositories tutorial.

Original Article

Read the complete tutorial with detailed explanations here:
https://www.javapro.academy/testing-spring-data-jpa-repositories/

What's Inside

This repository includes working Java examples demonstrating:

  • Setting up repository tests with @DataJpaTest
  • Using TestEntityManager to insert test data independently
  • Testing derived query methods (e.g., findByDepartment)
  • Testing comparison queries with boundary conditions
  • Testing custom @Query JPQL methods with ordering
  • Testing projection interfaces and DTO queries
  • Why TestEntityManager is preferred over the repository for test setup

Prerequisites

  • Java 17 or higher
  • Maven (for dependency management)
  • Spring Boot 3.x

Running the Tests

Clone the repository:

git clone <your-repo-url>
cd testing-spring-data-jpa-repositories

Install dependencies:

mvn clean install

Run the tests:

mvn test

Or run the test class directly from your IDE (IntelliJ IDEA, Eclipse, VS Code).

Dependencies

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

Learn More

Visit JavaPro Academy for more Java tutorials and courses:
https://www.javapro.academy/

Last Updated: February 9, 2026