We may earn an affiliate commission when you visit our partners.
Course image
Udemy logo

Testing Spring Boot App with JUnit, Mockito & Testcontainers

Ramesh Fadatare (Java Guides)

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.

Read more

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.

Important note: This course 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 again and again.

Spring Boot is a very popular framework to develop 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

In this course, we will focus on building reactive REST APIs using annotation-based reactive components.

What you'll learn?

  • 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

  • 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

  • Learn Building Reactive"

    "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"

Enroll now

What's inside

Learning objectives

  • 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 spring boot application repository layer
  • Learn to unit test spring boot application service layer
  • Learn to unit test spring boot application controller layer - unit test rest api's
  • Learn how to do integration testing for the spring boot application
  • 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 talking with multiple layers - controller, service, and repository layers.
  • Learn to write integration tests using a testcontainers
  • Learn building reactive crud rest apis using spring webflux and mongodb
  • Learn unit testing reactive crud rest apis using junit and mockito
  • Learn integration testing reactive crud rest apis using webtestclient
  • Show more
  • Show less

Syllabus

Introduction
Course overview and roadmap
Best Way to Take This Course and How to Get Help
What is Unit testing and Integration testing?
Read more
Best practices for Unit testing in Java
Download Source Code
Download All the Important Lecture Notes in PDF
JUnit 5 and Mockito Annotations Cheat Sheets
This Course Migrated to Spring Boot 3
Spring Boot Project Setup
Create and Set up Spring Boot Project in IntelliJ IDEA
Understanding Spring boot starter test dependency
Create JPA Entity
Create Spring Data JPA repository
End of this section of lectures, students should able to write Unit tests for Spring Data JPA repository layer components.
Repository layer Unit testing overview
Spring Boot @DataJpaTest annotation
Unit test for save employee operation
Unit test for get all employees operation
Unit test for get employee by id operation
Unit test for get employee by email operation (Spring Data JPA query method)
Unit test for update employee operation
Unit test for delete employee operation
Unit test Spring Data JPA custom query method using JPQL with index parameters
Unit test Spring Data JPA custom query method using JPQL with named parameters
Unit test Spring Data JPA custom native query with index parameters
Unit test Spring Data JPA custom Native query with Named parameters
Refactoring JUnit tests to use @BeforeEach annotation
Download source code of this section
Unit test deleteEmployee REST API
End of this section of lectures, students should able to write Unit tests for Service layer components.
Service Layer unit testing overview
Create EmployeeService with saveEmployee method
Quick Recap of Mockito basics (before writing JUnit tests to use Mock objects)
Unit test for EmployeeService saveEmployee method
Using @Mock and @InjectMocks annotations to mock the object
Unit test for saveEmployee method which throws Exception
Unit test for EmployeeService getAllEmployees method - Positive Scenario
Unit test for EmployeeService getAllEmployees method - Negative Scenario
Unit test for EmployeeService getEmployeeById method
Unit test for EmployeeService updateEmployee method
Unit test for EmployeeService deleteEmployee method
End of this section of lectures, students should able to write Unit tests for controller layer components (Unit test REST APIs).
Controller Layer unit testing overview
Overview of @WebMvcTest annotation
@WebMvcTest VS @SpringBootTest
Build createEmployee REST API
Unit test createEmployee REST API
Build GetAllEmployees REST API
Unit test GetAllEmployees REST API
Refactoring JUnit test to use static imports
Build getEmployeeById REST API
Unit test getEmployeeById REST API - Positive Scenario
Unit test getEmployeeById REST API - Negative Scenario
Build updateEmployee REST API
Unit test updateEmployee REST API - Positive Scenario
Unit test updateEmployee REST API - Negative Scenario
Build deleteEmployee REST API
Solution for All the Assignments in One Video
End of this section of lectures, students should able to write Integration tests for Spring boot application using MySQL database
Integration testing overview
@SpringBootTest annotation overview
Configure MySQL database for integration testing
Create a base for Integration testing
Integration test for create employee REST API
Integration test for get all employees REST API
Integration test for get employee by id REST API - Positive & Negative Scenarios
Integration test for update employee REST API - Positive & Negative Scenarios
Integration test for delete employee REST API
Integration testing EmployeeRepository using MySQL database
End of this section of lectures, students should able to write Integration tests for Spring boot application using Testcontainers
What problem does Testcontainers solve
Testcontainers overview
Adding Testcontainers
Integration Testing EmployeeController using Testcontainers
Using @DynamicPropertySource
Singleton containers pattern
Integration Testing EmployeeRepository using Testcontainers

You can download the source code of this section as a zip file (attached to this lecture)

Assignments and Solutions
Assignments for You
Quiz - Test Yourself
Quiz to Test Knowledge About This Course
Spring WebFlux - Build Reactive CRUD REST APIs
Spring WebFlux Overview
Spring Boot WebFlux Application Architecture
Deploy MongoDB in Docker Container
Create and Set up Spring Boot Project in IntelliJ IDE
Create Employee Entity
Create EmployeeRepository and Understanding Internals
Create EmployeeDto and EmployeeMapper
Build Reactive Add Employee REST API
Build Reactive Get Employee REST API
Build Reactive Get All Employees REST API
Build Reactive Update Employee REST API
Build Reactive Delete Employee REST API

Good to know

Know what's good
, what to watch for
, and possible dealbreakers
Demystifies Spring Boot and Spring WebFlux with emphasis on Reactive programming
Provides complete hands-on practice with Junit 5, Mockito, AssertJ, Hamcrest, JsonPath, and Testcontainers frameworks
Covers all layers of full stack testing with an emphasis on unit testing
Introduces Spring Boot Starter Test dependency for BDD style tests
Teaches industry-standard unit and integration testing practices
Employs a practical approach with clear step-by-step instructions

Save this course

Save Testing Spring Boot App with JUnit, Mockito & Testcontainers to your list so you can find it easily later:
Save

Activities

Be better prepared before your course. Deepen your understanding during and after it. Supplement your coursework and achieve mastery of the topics covered in Testing Spring Boot App with JUnit, Mockito & Testcontainers with these activities:
Review key Java fundamentals
Reinforces core concepts of Java by revisiting key concepts before starting the course.
Browse courses on Java Basics
Show steps
  • Review the Java SE Tutorial
  • Complete Java SE Tutorial exercises
  • Solve Java coding problems (e.g., LeetCode)
Follow online tutorials on JUnit 5 and Mockito
Provides hands-on practice with the testing frameworks used in the course.
Show steps
  • Find tutorials on JUnit 5 and Mockito
  • Follow the tutorials and complete the exercises
Write unit tests for Spring Boot application components
Strengthens understanding of unit testing and its implementation in Spring Boot applications.
Show steps
  • Create a simple Spring Boot application
  • Write unit tests for the application components (e.g., repository, service, controller)
  • Run the unit tests and debug any failures
Show all three activities

Career center

Learners who complete Testing Spring Boot App with JUnit, Mockito & Testcontainers will develop knowledge and skills that may be useful to these careers:

Reading list

We haven't picked any books for this reading list yet.

Share

Help others find this course page by sharing it with your friends and followers:

Similar courses

Here are nine courses similar to Testing Spring Boot App with JUnit, Mockito & Testcontainers.
Build Reactive MicroServices using Spring...
Most relevant
Reactive Streams Using Spring WebFlux 6
Most relevant
Reactive Streams Using Spring WebFlux 5
Most relevant
JUnit and Mockito Crash Course
Most relevant
Testing Spring Boot: Beginner to Guru
Most relevant
Spring Framework 5: Beginner to Guru
Most relevant
Spring Framework 6: Beginner to Guru
Most relevant
Event-Driven Microservices: Spring Boot, Kafka and Elastic
Most relevant
The Complete Spring Boot Development Bootcamp
Most relevant
Our mission

OpenCourser helps millions of learners each year. People visit us to learn workspace skills, ace their exams, and nurture their curiosity.

Our extensive catalog contains over 50,000 courses and twice as many books. Browse by search, by topic, or even by career interests. We'll match you to the right resources quickly.

Find this site helpful? Tell a friend about us.

Affiliate disclosure

We're supported by our community of learners. When you purchase or subscribe to courses and programs or purchase books, we may earn a commission from our partners.

Your purchases help us maintain our catalog and keep our servers humming without ads.

Thank you for supporting OpenCourser.

© 2016 - 2024 OpenCourser