Master Java Unit Testing with Spring Boot and Mockito

Master Java Unit Testing with Spring Boot and Mockito
Master Java Unit Testing with Spring Boot and Mockito
English | MP4 | AVC 1280×720 | AAC 44KHz 2ch | 3h 55m | 545 MB

Learn to Write Awesome Java JUnit Unit Tests with Spring Boot and Mockito in 40 Easy Steps

Spring Boot is the most popular framework to develop RESTful services. It has awesome unit testing capabilities through Spring Boot Starter Test. Mockito is the most popular mocking framework. JUnit is the most popular Java unit testing framework. You will build the unit tests step by step – in 40 easy steps. This course would be a perfect first step as an introduction to unit testing with the Spring Boot and Mockito frameworks. You will be using Spring (dependency management), Spring Boot, Maven (dependencies management), Eclipse (IDE), in memory database H2 and Tomcat embedded web server. We will help you set up each one of these. You will use all the frameworks that are part of the Spring Boot Starter Test – JUnit, Spring Test, Spring Boot Test, AssertJ, Hamcrest, Mockito, JSONassert and JsonPath. You will learn to use the most important unit testing annotations – @RunWith(SpringRunner.class), @SpringBootTest, @WebMvcTest, @DataJpaTest and @MockBean.

In this course, you will learn to build unit tests for simple RESTful services with Spring Boot Starter Test, Mockito and JUnit.

What You Will Learn

  • You will learn to write great Unit and Integration tests using Spring Boot Starter Test
  • You will learn to write unit tests using Mocks and Spys created with Mockito
  • You will learn to write independent unit tests for RESTful web services talking with multiple layers – web, business and data
  • You will learn to use the most important Unit Testing Annotations – @RunWith(SpringRunner), @SpringBootTest, @WebMvcTest, @DataJpaTest, and @MockBean.
  • You will learn to use all the frameworks that are part of Spring Boot Starter Test – JUnit, Spring Test, Spring Boot Test, AssertJ, Hamcrest, Mockito, JSONassert, and JsonPath.
  • You will learn to write integration tests using an in-memory database – H2
Table of Contents

Introduction
1 Course Overview
2 Introduction

Mocking With Mockito
3 Step 00 – Section Introduction – Mocking with Mockito
4 Step 01 – Setting up the project using Spring Initializr
5 Step 02 – Writing Unit Test for a Simple Business Service
6 Step 03 – Setting up a Business Service to call a Data Service
7 Step 04 – Writing your first unit test with Stub
8 Step 05 – Exercise Solution – Updating Tests 2 & 3 to use Stubs
9 Step 06 – Writing Unit Tests with Mocking using Mockito
10 Step 07 – Exercise Solution – Updating Tests 2 & 3 to use Mockito
11 Step 08 – More Refactoring – @Mock, @InjectMocks and @RunWith(MockitoJUnitRunner
12 Step 09 – Mockito Tips – Multiple Return Values and Specific Argument Matchers
13 Step 10 – Mockito Tips – Argument Matchers
14 Step 11 – Mockito Tips – Verify method calls
15 Step 12 – Mockito Tips – Argument Capture
16 Step 13 – Mockito Tips – Argument Capture on Multiple Calls
17 Step 14 – Introduction to Spy
18 Step 15 – Mockito FAQ

Unit Testing With Spring Boot and Mockito
19 Step 00 – Section Introduction – Unit Testing with Spring Boot and Mockito
20 Step 01 – Creating a Hello World Controller
21 Step 02 – Using Mock Mvc to test Hello World Controller
22 Step 03 – Using Response Matchers to check status and content
23 Step 04 – Creating a Basic REST Service in Item Controller
24 Step 05 – Unit Testing Item Controller and Basic JSON Assertions
25 Step 06 – Digging deeper into JSON Assert
26 Step 07 – Writing a REST Service talking to Business Layer
27 Step 08 – Writing Unit Test for REST Service mocking Business Layer
28 Step 09 – 00 – Overview of Steps 09 to 15
29 Step 09 – 01 – Prepare Data Layers with JPA, Hibernate and H2
30 Step 10 – Create Item Entity and Populate data with data.sql
31 Step 11 – Create a RESTful Service talking to the database
32 Step 12 – Writing Unit Test for Web Layer – Controller – Using Mock MVC
33 Step 13 – Exercise & Solution – Writing Unit Test for Business Layer – Mocking
34 Step 14 – Writing Unit Test for Data Layer – Data JPA Test
35 Step 15 – Writing an Integration Test using @SpringBootTest
36 Step 16 – Tip – Using @MockBean to mock out dependencies you do not want to talk
37 Step 17 – Tip – Creating Different Test Configuration
38 Step 18 – Writing Unit Tests for Other Request Methods
39 Step 19 – Refactor SomeBusinessImpl to use Functional Programming
40 Step 20 – Better Assertions with Hamcrest – HamcrestMatcherTest
41 Step 21 – Better Assertions with AssertJ – AssertJTest
42 Step 22 – Better Assertions with JSONPath – JSONPathTest
43 Step 23 – Tip Patterns – xunitpatterns
44 Step 24 – Tip – Measuring Test Coverage with Eclipse
45 Step 25 – Tip – Keep an eye on performance of unit tests!
46 Step 26 – Good Unit Tests

Congratulations
47 Next Steps