Test-Driven Development in Spring Boot with JUnit and Mockito
2h 8mAdvanced2025-01-15
Authors
Maaike van Putten
Trainer and Developer for Java, Python, Spring Boot, and More
Course details
If you’ve ever run out of time to write tests for your code, you know what a potential disaster you’re flirting with. Test-driven development (TDD) lets you write the test before the implementation code, essentially using the test to guide your development process. This course shows you how to apply TDD principles with Spring Boot projects. No prior knowledge of TDD is assumed, so instructor Maaike van Putten starts off by introducing TDD and showing a plain example. Then, move on to setting up the environment that will be used so you can follow along. After that, find out how to develop the different layers of a REST API the TDD way: controller layer, service layer, and the repository/data layer. Finally, Maaike wraps up the course up with some TDD best practices.
Learning objectives
Apply TDD principles with Spring Boot projects.
Use JUnit and Mockito in a TDD environment.
Understand how to test the different layers of a Spring Boot REST API.
Learning objectives
Apply TDD principles with Spring Boot projects.
Use JUnit and Mockito in a TDD environment.
Understand how to test the different layers of a Spring Boot REST API.
Skills covered
JUnitSpring BootJavaWeb Development ToolsAdvancedOracleSoftware Development ToolsWeb DevelopmentProgramming LanguagesOpen SourceSoftware Development
Concepts
0. Introduction
- 01 - Test-driven development in Spring Boot
1. TDD and Spring Boot
- 02 - Introduction to TDD in Spring Boot
- 03 - Setting up the development environment
2. Writing Your First TDD Test
- 04 - Red phase - Write a failing test
- 05 - Green phase - Implement the minimal code to pass the test
- 06 - Refactor phase - Improve the code quality
- 07 - Repeat - Adding more features
3. TDD for the Data Layer
- 08 - Writing TDD test for the repository
- 09 - Implementing the repository
- 10 - Integration testing with an in-memory database
- 11 - Refactoring the data layer
- 12 - Repeat - Adding the rest of the data layer
4. TDD for Services with Mockito
- 13 - Quick overview of working with Mockito
- 14 - Writing a TDD test for the service layer
- 15 - Implementing the method in the service layer
- 16 - Refactoring the service
- 17 - Repeat - Adding the rest of the service layer
5. TDD for Controllers and RESTful APIs
- 18 - Working with MockMvc
- 19 - Writing the first TDD test for the controller
- 20 - Implementing the method of the controller
- 21 - Refactoring the first method of the controller
- 22 - Repeat - Adding the rest of the controller layer
6. TDD Best Practices
- 23 - Common pitfalls to avoid
- 24 - Best practices for writing maintainable tests
- 25 - TDD workflow in real projects
Conclusion
- 26 - Next steps
Related courses
- Spring: Test-Driven Development with JUnit
- Spring Boot: Test-Driven Development
- Test-Driven Development in C++
- Test-Driven Development in Django
- Test-Driven Development in an AI World
- Unit Testing and Test Driven Development in Python
- Introduction to Agile Development Practices: Bring Agile to Your Development Pipelines
- Testing in React: Beyond Unit Tests