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
Table of contents
- Chapter 1 : Introduction
-
Chapter 2 : Mocking with Mockito
- Step 00 - Section Introduction - Mocking with Mockito
- Step 01 - Setting Up the Project Using Spring Initializr
- Step 02 - Writing a 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
- Step 05 - Exercise Solution - Updating Tests 2 and 3 to Use Stub
- Step 06 - Writing Unit Tests with Mocking Using Mockito
- Step 07 - Exercise Solution - Updating Tests 2 and 3 to Use Mockito
- Step 08 - More Refactoring - @Mock, @InjectMocks, and @RunWith(MockitoJUnitRunner)
- 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 FAQs
-
Chapter 3 : Unit Testing with Spring Boot and Mockito
- Step 00 - Section Introduction - Unit Testing with Spring Boot and Mockito
- Step 01 - Creating a Hello World Controller
- Step 02 - Using MockMvc to Test the 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 JSONassert
- Step 07 - Writing a REST Service talking to Business Layer
- Step 08 - Writing Unit Test for REST Service Mocking Business Layer
- Step 09 - 00 - Overview of Steps 09 to 15
- Step 09 - 01 - 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 MockMvc
- Step 13 - Exercise and 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 that are Not Required
- 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 - Tip Patterns ? xunitpatterns
- Step 24 - Tip - Measuring Test Coverage with Eclipse
- Step 25 - Tip - Keep an Eye on Performance of Unit Tests!
- Step 26 - Good Unit Tests
- Chapter 4 : Congratulations
Product information
- Title: Master Java Unit Testing with Spring Boot and Mockito
- Author(s):
- Release date: May 2018
- Publisher(s): Packt Publishing
- ISBN: 9781789346077
You might also like
book
The Complete Coding Interview Guide in Java
Explore a wide variety of popular interview questions and learn various techniques for breaking down tricky …
video
React - The Complete Guide (Includes Hooks, React Router, and Redux) - Second Edition
**This course is now updated for the latest version of React—React 18** React.js is the most …
book
Java Coding Problems
Develop your coding skills by exploring Java concepts and techniques such as Strings, Objects and Types, …
book
Java Challenges: 100+ Proven Tasks that Will Prepare You for Anything
Expand your knowledge of Java with this entertaining learning guide, which features 100+ exercises and programming …