Skip to main content

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
By connecting students all over the world to the best instructors, Udemy is helping individuals reach their goals and pursue their dreams. Udemy is the leading global marketplace for teaching and learning, connecting millions of students to the skills they need to succeed. Udemy helps organizations of all kinds prepare for the ever-evolving future of work. Our curated collection of top-rated business and technical courses gives companies, governments, and nonprofits the power to develop in-house expertise and satisfy employees’ hunger for learning and development.

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