
Learn to test Spring Boot apps with unit and integration tests using JUnit 5 and Mockito, covering repository, service, and controller layers with DataJpaTest and given/when/then BDD style.
Learn the basic JUnit concepts, including system under test, method under test, test class, test method, assertions, and the test runner that executes tests in development environments and build tools.
Set up a Maven project in IntelliJ with Java 21 and add JUnit dependencies via pom.xml, preparing the environment for JUnit tests in Spring Boot testing.
Write your first JUnit test for a calculator add method in a maven project using JUnit Jupiter. Annotate with @Test and use assertEquals to verify expected versus actual results.
Master the JUnit @Test annotation that marks a method as a test and lets JUnit automatically run all tests in a class, with imports from org.junit.jupiter.api.
Learn how to use the JUnit 5 assertTrue method to verify boolean conditions, including direct boolean checks, boolean supplier lazy evaluation, and custom messages with a student list example.
Explore the assert false method in JUnit 5, its overloaded forms, and how to verify a condition is false using static assertions, custom messages, and lazy evaluation with boolean suppliers.
Demonstrate using the assert equals method in JUnit to verify that actual values equal expected values, including overloaded forms for ints, objects, custom messages, and lazy evaluation via a supplier.
Explore how to use JUnit's assertNotEquals method to verify that actual and expected values are not equal, including overloaded variants and custom failure messages.
Explore how to use JUnit's assertArrayEquals to verify two arrays match exactly, including order and length, with overloaded versions, custom messages, and lazy messages through a supplier.
Learn how to use JUnit's assertIterableEquals method to verify two iterables are deeply equal by checking elements, order, and size, including overloads and lazy messages.
Use JUnit's assertThrows to verify that code throws a specific exception, explore its three overloads with executable and supplier-based messages, and understand inheritance with a student not found example.
Explore the assertThrowsExactly method in JUnit to verify that code throws the exact exception type, not a superclass, with examples, overloads, and lazy-evaluated messages.
Use the @DisplayName annotation in JUnit 5 to customize test class and method names, improving readability of results; the calculator demo covers add, subtract, multiply, and divide.
Use the @Disabled annotation in JUnit 5 to skip specific tests or test classes. Understand scenarios for disabling: known issues, incomplete features, refactoring, and external dependencies, with a calculator example.
Discover how JUnit lifecycle annotations control test execution with before each, after each, before all, and after all, enabling per-test setup and global cleanup.
Explains how the @BeforeEach annotation runs before every test method, enabling a shared setup that initializes the calculator and reduces duplicate code for a clean test state.
Explore the @AfterEach annotation in JUnit to run cleanup after every test, closing resources and resetting state for isolated test methods.
Use the @BeforeAll annotation to run a static setup method once before all tests in a class. This shares expensive resources such as a database connection or a server.
Annotate a method with @AfterAll to run cleanup after all test methods in a class, and declare it static to release resources such as closing database connections.
Explore JUnit 5 nested tests using the @Nested annotation to organize related test methods in non-static inner classes, enabling hierarchical, isolated setup and deep test grouping in a calculator example.
Explore parameterized testing with @CsvSource in JUnit 5, verifying a factorial method across multiple input and expected pairs and learning to set up, run, and assert test results.
Learn to use @CsvFileSource to load test data from an external CSV file for parameterized tests, configure the sources attribute, and run tests with multiple parameters in Spring Boot testing.
Explore parameterized tests with method source in JUnit 5, using a static arguments provider to supply streams of arguments for factorial tests.
Create a custom arguments provider by implementing the arguments provider interface, supply a stream of values to parameterized tests with @ArgumentsSource in JUnit Jupiter.
In this course, you will learn how to write Unit tests and Integration tests in BDD style for Spring Boot applications as well as Spring WebFlux applications using JUnit 5, Mockito, AssertJ, Hamcrest, JsonPath, and Testcontainers frameworks.
Recent update: I have added lectures on JUnit 5 fundamentals.
Important note: This course is updated to use Spring Boot 3.
Type the code along with me in the videos. If you follow along with me, then this will enhance your learning experience.
The source code and PDF files (class notes) are available for download.
Spring Boot Overview
Spring Boot is an opinionated framework that helps developers build Spring-based applications quickly and easily.
The main goal of Spring Boot is to quickly create Spring-based applications without requiring developers to write the same boilerplate configuration repeatedly.
Spring Boot is a popular framework for developing REST web services and microservices.
Spring WebFlux Overview
Spring 5 includes Spring WebFlux, which provides reactive programming support for web applications.
Spring WebFlux internally uses Project Reactor and its publisher implementations, Flux and Mono.
The new framework supports two programming models:
Annotation-based reactive components
Functional routing and handling
This course will focus on building reactive REST APIs using annotation-based reactive components.
What you'll learn?
Learn JUnit 5 framework fundamentals.
Learn to write industry-standard Unit and Integration tests in BDD (Behaviour Driven Development) style using Spring Boot Starter Test dependency from scratch.
Learn how to use BDD (Behaviour Driven Development) format that is given/when/then to write Unit tests.
Learn to Unit test the Spring boot application Repository layer
Learn to Unit test the Spring boot application Service layer
Learn to Unit test the Spring boot application Controller layer
Learn how to do Integration testing for the Spring boot application.
Learn how to do Integration testing using Testcontainers // very important
You will learn to use the most important Unit Testing ANNOTATIONS - @SpringBootTest, @WebMvcTest, @DataJpaTest, and @MockBean
Use ALL the FRAMEWORKS in Spring Boot Starter Test - JUnit, Spring Test, Spring Boot Test, AssertJ, Hamcrest, Mockito, JSONassert, and JsonPath.
You will learn to write Unit tests using Mocks and Stubs created with Mockito.
Learn how to use Mockito annotations to create mock objects.
Learn to Write Integration Tests using a MySQL database.
You will learn to Write INDEPENDENT Integration tests for RESTFUL web services by talking with MULTIPLE LAYERS - controller, service, and repository layers.
Learn Building Reactive CRUD REST APIs using Spring WebFlux
Learn Unit Testing Reactive CRUD REST APIs
Learn Integration Testing Reactive CRUD REST APIs
Tools and Technologies used in this course:
Technologies and Libraries:
Java 11+
Spring Boot
Spring MVC
Spring Data JPA ( Hibernate)
JUnit 5 Framework
Mockito 4 (Latest)
Hamcrest framework
AssertJ Library
JsonPath Library
Spring WebFlux
MongoDB
IDE:
IntelliJ IDEA
Database:
H2 In-memory database ( for repository layer testing)
MySQL database ( for Integration testing)
MongoDB database (for Integration testing)
Excellent reviews from Students on this course:
"Ramesh is a great teacher; he provides very clear explanations of complex concepts."
"Ramesh explains things very well! His instructions are easy to follow and understand. The course is very beneficial."
- Well structured course covering all layers of testing
- Implement each method with the "right to the point" explanation
- Nice introduction to TestContainers
- Easy to code along
- Fast answers from the instructor
Looking for more deep dives courses such as Maven, Gradle, DevOps tools used in production."
"Awesome course.
All the basics needed to test a spring application are discussed, and more.
Exactly what i needed and coudn't find anywhere.
Ramesh is a great instructor.
Thank you sir !"
"A very good course explained with excellent examples.
Lot to learn from this course, covered every layer of a typical Spring Boot application."
"I really appreciate the trainer Ramesh to providing is this amazing course,
the content of this course and explanation is great."
"Wonderful Sir, Loved the way u explain things. And I am very lucky that I found this course at right time."
"I am personally very impressed with this course, if you dont have any prior experience of unit testing I am pretty sure that after taking this course you will feel more confident and I would be happy if the lecturer could also release some training tutorials about Microservices and TDD approach. thanks and wish you all the successes."
"Even though as a experience guy, this course was very useful.."
"The course is great and covers all I need to create my tests.
I truly recommend it ."
"Great course. This is the second course I am taking from Ramesh. Interesting so far."
"Awesome course and highly recommend it."
"This course is a good match for me. Especially so because it's new and up to date."
"great teacher and great course"
"Yes this is a good match for me and I am glad I enrolled for this. I personally prefer teaching of ramesh.fadatare. I started to watch his videos from YouTube and also gone through his comments to few problems in stack overflow. I thought it would be good if I can go through all his videos in one go."
"this is what they ask you to do on a real job... please do more courses ramesh.. amazing as always"