Skip to main content
CF

Master Java Unit Testing with Spring Boot & Mockito

3h 56m 12s
English
Paid

Master the art of unit testing with the powerful combination of Spring Boot and Mockito. Learn how to develop robust and efficient RESTful Services by harnessing the capabilities of these popular frameworks.

Course Overview

In this comprehensive course, you will discover how to write exceptional unit tests for simple RESTful services using Spring Boot Starter Test, Mockito, and JUnit. This course will guide you in writing independent unit tests for RESTful web services that interact with multiple layers: web, business, and data. Additionally, you will master the art of writing integration tests utilizing an in-memory database H2.

Course Structure

Step-by-Step Guide

Embark on a journey of 40 comprehensive steps designed to introduce you to unit testing with the Spring Boot and Mockito frameworks.

Tools and Technologies

Throughout the course, you will work with Spring (Dependency Management), Spring Boot, Maven (dependencies management), Eclipse (IDE), in-memory database H2, and the Tomcat Embedded Web Server. We will assist you in setting up each of these tools.

Frameworks and Libraries

You will explore a variety of frameworks included in Spring Boot Starter Test, including JUnit, Spring Test, Spring Boot Test, AssertJ, Hamcrest, Mockito, JSONassert, and JsonPath.

Key Annotations

Enhance your skills by learning to use the most critical unit testing annotations: @RunWith(SpringRunner.class), @SpringBootTest, @WebMvcTest, @DataJpaTest, and @MockBean.

Course Content

Section 1: Learning Mocking with Mockito

  • Step 01: Setting up the project using Spring Initializr
  • Step 02: Writing a Unit Test for a Simple Business Service
  • ... (and other steps)

Section 2: Unit Testing RESTful Services

  • Step 01: Creating a Hello World Controller
  • Step 02: Using Mock Mvc to Test Hello World Controller
  • ... (and other steps)

Requirements

  • A willingness to learn and have fun :)
  • Basic working knowledge of Java, JUnit, Spring, Spring Boot, and JPA/Hibernate.
  • Assistance in installing Eclipse and getting started with Maven and Tomcat is provided.

Who Should Enroll

  • Spring/Spring Boot/Java Programmers who aim to write outstanding unit tests for RESTful Services
  • Developers interested in using mocking for unit tests
  • Those who want to understand the best practices in writing superior unit tests with JUnit, Mockito, and Spring Boot Starter Test
  • Learners eager to employ Hamcrest Matchers, JSON Assert, Assert J, and JSON Path libraries for effective assertions

Learning Outcomes

  • Proficiency in writing GREAT UNIT and INTEGRATION Tests using Spring Boot Starter Test from the ground up
  • Skill in creating INDEPENDENT Unit Tests for RESTFUL web services interacting with MULTIPLE LAYERS
  • Mastery of essential Unit Testing ANNOTATIONS like @SpringBootTest, @WebMvcTest, @DataJpaTest, and @MockBean
  • Utilization of all frameworks in Spring Boot Starter Test including JUnit, AssertJ, and Mockito
  • Expertise in writing unit tests employing MOCKS and SPYS created with MOCKITO
  • Capability to write Integration Tests using an IN MEMORY DATABASE - H2

About the Author: Udemy

Udemy thumbnail

Udemy is the largest open marketplace for online courses on the internet. Founded in 2010 by Eren Bali, Oktay Caglar, and Gagan Biyani and headquartered in San Francisco, the company went public on the Nasdaq in 2021 under the ticker UDMY. The platform hosts well over two hundred thousand courses across software development, IT and cloud, data science, design, business, marketing, and creative skills, taught by tens of thousands of independent instructors. Roughly seventy million learners use it worldwide, and the corporate arm — Udemy Business — supplies a curated subset of that catalog to enterprise customers.

Because Udemy is a marketplace rather than a single editorial publisher, the catalog is uneven by design. The strongest material lives in the long-form, project-based courses authored by working engineers — full-stack JavaScript, React, Node.js, Python data science, AWS, Docker and Kubernetes, mobile development with Flutter and React Native, and cloud certification preparation. The CourseFlix listing under this source is the slice of that catalog that has been mirrored here for offline-friendly viewing, organized by topic and updated as new releases land. Pricing on Udemy itself swings dramatically with the site's near-permanent sales, which is why the platform is best treated as a deep reference catalog: pick instructors with strong reviews and a track record of updating their material rather than buying on the headline price alone.

Watch Online 47 lessons

This is a demo lesson (10:00 remaining)

You can watch up to 10 minutes for free. Subscribe to unlock all 47 lessons in this course and access 10,000+ hours of premium content across all courses.

View Pricing
0:00
/
#1: Introduction
All Course Lessons (47)
#Lesson TitleDurationAccess
1
Introduction Demo
03:26
2
Course Overview
02:13
3
Step 00 - Section Introduction - Mocking with Mockito
01:33
4
Step 01 - Setting up the project using Spring Initializr
02:57
5
Step 02 - Writing Unit Test for a Simple Business Service
06:04
6
Step 03 - Setting up a Business Service to call a Data Service
03:50
7
Step 04 - Writing your first unit test with Stub
04:57
8
Step 05 - Exercise Solution - Updating Tests 2 & 3 to use Stubs
03:48
9
Step 06 - Writing Unit Tests with Mocking using Mockito
05:39
10
Step 07 - Exercise Solution - Updating Tests 2 & 3 to use Mockito
04:12
11
Step 08 - More Refactoring - @Mock, @InjectMocks and @RunWith(MockitoJUnitRunner
03:26
12
Step 09 - Mockito Tips - Multiple Return Values and Specific Argument Matchers
05:53
13
Step 10 - Mockito Tips - Argument Matchers
02:59
14
Step 11 - Mockito Tips - Verify method calls
06:41
15
Step 12 - Mockito Tips - Argument Capture
04:05
16
Step 13 - Mockito Tips - Argument Capture on Multiple Calls
02:34
17
Step 14 - Introduction to Spy
07:43
18
Step 15 - Mockito FAQ
03:25
19
Step 00 - Section Introduction - Unit Testing with Spring Boot and Mockito
02:47
20
Step 01 - Creating a Hello World Controller
03:41
21
Step 02 - Using Mock Mvc to test Hello World Controller
12:41
22
Step 03 - Using Response Matchers to check status and content
05:08
23
Step 04 - Creating a Basic REST Service in Item Controller
05:09
24
Step 05 - Unit Testing Item Controller and Basic JSON Assertions
04:06
25
Step 06 - Digging deeper into JSON Assert
12:27
26
Step 07 - Writing a REST Service talking to Business Layer
04:11
27
Step 08 - Writing Unit Test for REST Service mocking Business Layer
06:52
28
Step 09 - 00 - Overview of Steps 09 to 15
01:42
29
Step 09 - 01 - Prepare Data Layers with JPA, Hibernate and H2
03:25
30
Step 10 - Create Item Entity and Populate data with data.sql
06:01
31
Step 11 - Create a RESTful Service talking to the database
07:55
32
Step 12 - Writing Unit Test for Web Layer - Controller - Using Mock MVC
06:12
33
Step 13 - Exercise & Solution - Writing Unit Test for Business Layer - Mocking
05:28
34
Step 14 - Writing Unit Test for Data Layer - Data JPA Test
08:02
35
Step 15 - Writing an Integration Test using @SpringBootTest
08:52
36
Step 16 - Tip - Using @MockBean to mock out dependencies you do not want to talk
05:04
37
Step 17 - Tip - Creating Different Test Configuration
03:41
38
Step 18 - Writing Unit Tests for Other Request Methods
03:29
39
Step 19 - Refactor SomeBusinessImpl to use Functional Programming
03:50
40
Step 20 - Better Assertions with Hamcrest - HamcrestMatcherTest
08:38
41
Step 21 - Better Assertions with AssertJ - AssertJTest
06:28
42
Step 22 - Better Assertions with JSONPath - JSONPathTest
09:39
43
Step 23 - Tip Patterns - xunitpatterns
01:23
44
Step 24 - Tip - Measuring Test Coverage with Eclipse
04:26
45
Step 25 - Tip - Keep an eye on performance of unit tests!
03:04
46
Step 26 - Good Unit Tests
05:35
47
Next Steps
00:51
Unlock unlimited learning

Get instant access to all 46 lessons in this course, plus thousands of other premium courses. One subscription, unlimited knowledge.

Learn more about subscription

Related courses

Frequently asked questions

What are the prerequisites for this course?
Before enrolling in this course, students should have a basic understanding of Java programming. Familiarity with web services and the Spring framework would be beneficial but not mandatory. The course will guide you through setting up necessary tools like Spring Boot and Maven, so prior experience with these tools is not required.
What projects will I build during the course?
Throughout the course, you will write unit tests for simple RESTful services using Spring Boot and Mockito. You will work on creating a RESTful service in the Item Controller and perform unit testing for various layers, including web, business, and data layers. Integration tests are also covered using an in-memory database H2, allowing you to test the full application stack.
Who is the target audience for this course?
This course is ideal for Java developers who want to enhance their skills in unit testing with Spring Boot and Mockito. Whether you are a beginner in testing or have some experience, the step-by-step approach will help in mastering the art of writing effective unit tests for RESTful services.
How does the course compare in depth and scope to other courses?
This course offers a detailed exploration of unit testing specifically tailored for Java RESTful services. With 47 lessons, it covers various frameworks and tools such as JUnit, Mockito, and Spring Boot Starter Test. It also delves into specific testing annotations, providing a comprehensive understanding that may go beyond what is covered in more general Java or Spring Boot courses.
What specific tools and platforms will I learn to use?
The course will teach you to use several tools and platforms, including Spring Boot for application development, Mockito for mocking, and JUnit for testing. You will also work with Maven for dependency management, Eclipse as an Integrated Development Environment (IDE), and an in-memory database H2 for integration testing.
What topics are not covered in this course?
The course does not cover non-Java programming languages or frameworks outside the Spring ecosystem. Advanced topics such as microservices architecture, security testing, or performance testing are also beyond its scope. It focuses primarily on unit and integration testing for RESTful services using Java.
What is the expected time commitment for completing the course?
The course is structured into 47 lessons, each focusing on different aspects of unit testing. While the total runtime is not specified, students should allocate time for both the lectures and hands-on exercises. Depending on your pace and familiarity with the content, it may take several weeks to fully absorb and apply the concepts covered.