An open API service indexing awesome lists of open source software.

https://github.com/edsonwade/spring-testing-mastery

This repository is a practical and educational resource focused on testing Spring Boot applications across all architectural layers. It demonstrates how to write effective and maintainable tests using modern tools and techniques.
https://github.com/edsonwade/spring-testing-mastery

cucumber-java h2-database integration-testing java mockito-junit-test mockmvc testcontainers-junit-jupiter

Last synced: 3 months ago
JSON representation

This repository is a practical and educational resource focused on testing Spring Boot applications across all architectural layers. It demonstrates how to write effective and maintainable tests using modern tools and techniques.

Awesome Lists containing this project

README

          

# ๐Ÿงช Spring Testing Mastery

Welcome to the **Spring Testing Mastery** repository! This project is a comprehensive guide and hands-on resource for mastering testing in Spring applications. It covers everything from unit testing to full integration testing using modern tools and best practices.

## ๐Ÿ“š What This Repository Covers

Spring provides powerful testing capabilities, and this repository demonstrates how to use them effectively across all layers of a typical Spring MVC application:

### ๐ŸŽฏ Controller Layer
- Test your web endpoints using **MockMvc**
- Validate HTTP requests and responses
- Simulate user interactions and verify controller logic

### โš™๏ธ Service Layer
- Use **Mockito** to mock dependencies
- Write clean and isolated unit tests
- Apply **Behavior-Driven Development (BDD)** principles

### ๐Ÿ—„๏ธ Repository Layer
- Test data access logic with **Spring Data JPA**
- Use **Testcontainers** to spin up real databases for integration tests
- Ensure your repositories behave correctly with actual data

### ๐Ÿงช Testing Strategies
- **Unit Testing**: Isolate and test individual components
- **Slice Testing**: Focus on specific layers (e.g., `@WebMvcTest`, `@DataJpaTest`)
- **Integration Testing**: Verify end-to-end functionality across layers

### ๐Ÿฅ’ BDD with Cucumber
- Write human-readable test scenarios
- Connect Gherkin syntax to Spring test logic
- Promote collaboration between developers and QA

### ๐Ÿณ Testcontainers
- Run real database containers (e.g., PostgreSQL, MySQL) during tests
- Eliminate environment inconsistencies
- Improve reliability of integration tests

## ๐Ÿš€ Technologies Used
- Spring Boot
- JUnit 5
- Mockito
- MockMvc
- Cucumber
- Testcontainers
- Spring Data JPA

## ๐Ÿ“ Structure
```
๐Ÿ“ฆ spring-testing-mastery
โ”œโ”€โ”€ ๐Ÿงช unit-tests
โ”œโ”€โ”€ ๐Ÿงฉ slice-tests
โ”œโ”€โ”€ ๐Ÿ”— integration-tests
โ”œโ”€โ”€ ๐Ÿฅ’ bdd-cucumber
โ”œโ”€โ”€ ๐Ÿณ testcontainers
โ””โ”€โ”€ ๐Ÿ“š docs
```

## ๐Ÿ‘จโ€๐Ÿ’ป Author
**Edosnwade**
---