This project is a sample Spring Boot application with a focus on item management. It demonstrates various testing approaches such as unit testing, integration testing (IT), and mocking using different frameworks and libraries.
- Java 21: The latest stable version of Java.
- Spring Boot: Framework used for building production-ready applications.
- H2 Database: In-memory database for testing purposes.
- Mockito: A framework used for mocking dependencies in unit tests.
- JUnit 5: Framework for writing unit tests.
- JsonPath: Library for querying and extracting data from JSON documents.
- AssertJ: For fluent assertions in tests.
- Hamcrest: A library of matchers for more readable and expressive assertions.
The project contains the following main components:
-
Business Logic Layer:
ItemBusinessService: A service responsible for handling item data.SomeBusinessImpl: A service for some business logic involving data calculations.
-
Controller Layer:
ItemController: A REST controller that handles HTTP requests related to items.
-
Model Layer:
Item: A simple entity representing an item in the system.
-
Repository Layer:
ItemRepository: A Spring Data JPA repository for managing items.
-
Tests:
- Unit Tests: Tests focusing on individual components or methods.
- Integration Tests (IT): Tests verifying the interaction between components.
- Mocking Tests: Using Mockito to mock dependencies and test logic in isolation.
- JsonPath Tests: For testing responses from REST APIs by extracting data using JSONPath queries.
- AssertJ and Hamcrest Tests: For more readable assertions in unit tests.
- Java 21
- Maven for managing dependencies
- Spring Boot dependencies for building the app
To run the project, clone the repository and build the project using Maven:
git clone https://github.com/rvega1204/java-unit-testing.git
cd <project_directory>
mvn clean install
mvn clean testThis project is licensed under the MIT License.
This README outlines the project, its technologies, testing approaches, and some examples of the different tests used throughout. Feel free to clone it and modify it according to your needs.