Master Java Unit Testing with Spring Boot & Mockito

3h 56m 12s
English
Paid
May 1, 2024

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 most popular Java Unit Testing Framework.

More

In this course, you will learn to Write Great Unit Tests for Simple RESTful Services with Spring Boot Starter Test, Mockito and JUnit. You will learn to write independent unit tests for RESTful web services talking with multiple layers - web, business and data. You will learn how to write integration tests using an in memory database H2.

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

Step By Step Details

Section 1 - Learning Mocking with Mockito

  • Step 01: Setting up the project using Spring Initializr

  • Step 02: Writing Unit Test for a Simple Business Service

  • Step 03: Setting up a Business Service to call a Data Service

  • Step 04: Writing your first unit test with Stub

    • Exercise - Update Tests 2 & 3

  • Step 05: Exercise Solution - Updating Tests 2 & 3 to use Stubs - Problem with Stubs.

  • Step 06: Writing Unit Tests with Mocking using Mockito

    • Exercise - Updating Tests 2 & 3 to use Mockito

  • Step 07: Exercise Solution - Updating Tests 2 & 3 to use Mockito

  • Step 08: More Refactoring - @Mock, @InjectMocks and @RunWith(MockitoJUnitRunner.class)

  • Step 09: Mockito Tips - Multiple Return Values and Specific Argument Matchers

  • Step 10: Mockito Tips - Argument Matchers

  • Step 11: Mockito Tips - Verify method calls

  • Step 12: Mockito Tips - Argument Capture

  • Step 13: Mockito Tips - Argument Capture on Multiple Calls

  • Step 14: Introduction to Spy

  • Step 15: Mockito FAQ
    Section 2 - Unit Testing RESTful Services with Spring Boot and Mockito

  • Step 01: Creating a Hello World Controller

  • Step 02: Using Mock Mvc to test Hello World Controller

  • Step 03: Using Response Matchers to check status and content

  • Step 04: Creating a Basic REST Service in Item Controller

  • Step 05: Unit Testing Item Controller and Basic JSON Assertions

  • Step 06: Digging deeper into JSON Assert

  • Step 07: Writing a REST Service talking to Business Layer

  • Step 08: Writing Unit Test for REST Service mocking Business Layer

  • Step 09: Prepare Data Layers with JPA, Hibernate and H2

  • Step 10: Create Item Entity and Populate data with data.sql

  • Step 11: Create a RESTful Service talking to the database

  • Step 12: Writing Unit Test for Web Layer - Controller - Using Mock MVC

  • Step 13: Exercise & Solution - Writing Unit Test for Business Layer - Mocking

  • Step 14: Writing Unit Test for Data Layer - Data JPA Test

  • Step 15: Writing an Integration Test using @SpringBootTest

  • Step 16: Tip : Using @MockBean to mock out dependencies you do not want to talk to!

  • Step 17: Tip : Creating Different Test Configuration

  • Step 18: Writing Unit Tests for Other Request Methods

  • Step 19: Refactor SomeBusinessImpl to use Functional Programming

  • Step 20: Better Assertions with Hamcrest - HamcrestMatcherTest

  • Step 21: Better Assertions with AssertJ - AssertJTest

  • Step 22: Better Assertions with JSONPath - JSONPathTest

  • Step 23: Easier Static Imports

  • Step 24: Tip : Measuring Test Coverage with Eclipse

  • Step 25: Tip : Keep an eye on performance of unit tests!

  • Step 26: Good Unit Tests

Requirements:
  • You have an attitude to learn while having fun :)
  • You should have working knowledge of Java, Junit, Spring, Spring Boot and JPA/Hibernate.
  • We will help you install Eclipse and get up and running with Maven and Tomcat.
Who this course is for:
  • You are a Spring/Spring Boot/Java Programmer and You want to write awesome unit tests for your RESTful Services
  • You want to write awesome unit tests with mocking
  • You want to understand the best practices in writing great unit tests with JUnit, Mockito and Spring Boot Starter Test
  • You want to learn to write great asserts with Hamcrest Matchers, JSON Assert, Assert J and JSON Path libraries

What you'll learn:

  • You will learn to WRITE GREAT UNIT and INTEGRATION Tests using Spring Boot Starter Test from SCRATCH
  • 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 - @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 SPYS created with MOCKITO
  • You will learn to Write Integration Tests using an IN MEMORY DATABASE - H2

Watch Online Master Java Unit Testing with Spring Boot & Mockito

Join premium to watch
Go to premium
# Title Duration
1 Introduction 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

Similar courses to Master Java Unit Testing with Spring Boot & Mockito

Spring Boot E-Commerce Ultimate Course

Spring Boot E-Commerce Ultimate Courseudemy

Duration 83 hours 14 minutes 29 seconds
Learn Spring 5 and Spring Boot 2

Learn Spring 5 and Spring Boot 2baeldung

Duration 4 hours 57 minutes 32 seconds
Software Testing Masterclass - From Novice to Expert

Software Testing Masterclass - From Novice to Expertudemy

Duration 7 hours 34 minutes 23 seconds
Testing Laravel with PHPUnit

Testing Laravel with PHPUnitspatie.be

Duration 2 hours 42 minutes 59 seconds
OAuth 2.0 in Spring Boot Applications

OAuth 2.0 in Spring Boot Applicationsudemy

Duration 10 hours 54 minutes 34 seconds
Full Stack HATEOAS: Spring Boot 2.1, ReactJS, Redux

Full Stack HATEOAS: Spring Boot 2.1, ReactJS, Reduxudemy

Duration 5 hours 51 minutes 37 seconds