Master Java Unit Testing with Spring Boot and Mockito

Video description

Learn to write awesome Java JUnit unit tests with Spring Boot, Mockito, JSONassert, Hamcrest, and JSONPath in 40 easy steps.

About This Video

  • Build the unit tests step-by-step in 40 easy steps
  • Write independent unit tests for RESTful web services talking with multiple layers—web, business, and data
  • Write awesome unit tests for simple RESTful services with Spring Boot Starter Test, Mockito, and JUnit

In Detail

Spring Boot is the most popular framework to develop RESTful services. It has awesome unit testing capabilities through the 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 (dependency 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 also learn how to use the most important unit testing annotations: @RunWith(SpringRunner.class), @SpringBootTest, @WebMvcTest, @DataJpaTest, and @MockBean.

By the end of this course, you will be able to write awesome unit tests for your RESTful services.

Who this book 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 how to write great asserts with Hamcrest Matchers, JSONassert, Assert J, and JSON Path libraries.

Publisher resources

Download Example Code

Table of contents

  1. Chapter 1 : Introduction
    1. Introduction
    2. Course Overview
  2. Chapter 2 : Mocking with Mockito
    1. Step 00 - Section Introduction - Mocking with Mockito
    2. Step 01 - Setting Up the Project Using Spring Initializr
    3. Step 02 - Writing a Unit Test for a Simple Business Service
    4. Step 03 - Setting Up a Business Service to call a Data Service
    5. Step 04 - Writing Your First Unit Test with Stub
    6. Step 05 - Exercise Solution - Updating Tests 2 and 3 to Use Stub
    7. Step 06 - Writing Unit Tests with Mocking Using Mockito
    8. Step 07 - Exercise Solution - Updating Tests 2 and 3 to Use Mockito
    9. Step 08 - More Refactoring - @Mock, @InjectMocks, and @RunWith(MockitoJUnitRunner)
    10. Step 09 - Mockito Tips - Multiple Return Values and Specific Argument Matchers
    11. Step 10 - Mockito Tips - Argument Matchers
    12. Step 11 - Mockito Tips - Verify Method Calls
    13. Step 12 - Mockito Tips - Argument Capture
    14. Step 13 - Mockito Tips - Argument Capture on Multiple Calls
    15. Step 14 - Introduction to Spy
    16. Step 15 - Mockito FAQs
  3. Chapter 3 : Unit Testing with Spring Boot and Mockito
    1. Step 00 - Section Introduction - Unit Testing with Spring Boot and Mockito
    2. Step 01 - Creating a Hello World Controller
    3. Step 02 - Using MockMvc to Test the Hello World Controller
    4. Step 03 - Using Response Matchers to Check Status and Content
    5. Step 04 - Creating a Basic REST Service in Item Controller
    6. Step 05 - Unit Testing Item Controller and Basic JSON Assertions
    7. Step 06 - Digging Deeper into JSONassert
    8. Step 07 - Writing a REST Service talking to Business Layer
    9. Step 08 - Writing Unit Test for REST Service Mocking Business Layer
    10. Step 09 - 00 - Overview of Steps 09 to 15
    11. Step 09 - 01 - Prepare Data Layers with JPA, Hibernate, and H2
    12. Step 10 - Create Item Entity and Populate Data with data.sql
    13. Step 11 - Create a RESTful Service Talking to the Database
    14. Step 12 - Writing Unit Test for Web Layer - Controller - Using MockMvc
    15. Step 13 - Exercise and Solution - Writing Unit Test for Business Layer ? Mocking
    16. Step 14 - Writing Unit Test for Data Layer - Data JPA Test
    17. Step 15 - Writing an Integration Test Using @SpringBootTest
    18. Step 16 - Tip - Using @MockBean to Mock Out Dependencies that are Not Required
    19. Step 17 - Tip - Creating Different Test Configuration
    20. Step 18 - Writing Unit Tests for Other Request Methods
    21. Step 19 - Refactor SomeBusinessImpl to Use Functional Programming
    22. Step 20 - Better Assertions with Hamcrest ? HamcrestMatcherTest
    23. Step 21 - Better Assertions with AssertJ ? AssertJTest
    24. Step 22 - Better Assertions with JSONPath ? JSONPathTest
    25. Step 23 - Tip Patterns ? xunitpatterns
    26. Step 24 - Tip - Measuring Test Coverage with Eclipse
    27. Step 25 - Tip - Keep an Eye on Performance of Unit Tests!
    28. Step 26 - Good Unit Tests
  4. Chapter 4 : Congratulations
    1. Next Steps

Product information

  • Title: Master Java Unit Testing with Spring Boot and Mockito
  • Author(s): In28Minutes Official
  • Release date: May 2018
  • Publisher(s): Packt Publishing
  • ISBN: 9781789346077