Oreilly - Master Java Unit Testing with Spring Boot and Mockito
by Ranga Karanam | Released May 2018 | ISBN: 9781789346077
Learn to Write Awesome Java JUnit Unit Tests with Spring Boot and Mockito in 40 Easy StepsAbout This VideoLearn to write independent unit tests for RESTful web services talking with multiple layers - web, business, and data.Learn how to write integration tests using an in-memory database H2.In DetailSpring 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. Show and hide more Publisher resources Download Example Code
- Chapter 1 : Introduction
- Introduction 00:03:24
- Course Overview 00:02:12
- Chapter 2 : Mocking With Mockito
- Step 00 - Section Introduction - Mocking with Mockito 00:01:32
- Step 01 - Setting up the project using Spring Initializr 00:02:56
- Step 02 - Writing Unit Test for a Simple Business Service 00:06:03
- Step 03 - Setting up a Business Service to call a Data Service 00:03:49
- Step 04 - Writing your first unit test with Stub 00:04:56
- Step 05 - Exercise Solution - Updating Tests 2 & 3 to use Stubs 00:03:47
- Step 06 - Writing Unit Tests with Mocking using Mockito 00:05:38
- Step 07 - Exercise Solution - Updating Tests 2 & 3 to use Mockito 00:04:11
- Step 08 - More Refactoring - @Mock, @InjectMocks and @RunWith(MockitoJUnitRunner 00:03:25
- Step 09 - Mockito Tips - Multiple Return Values and Specific Argument Matchers 00:05:52
- Step 10 - Mockito Tips - Argument Matchers 00:02:58
- Step 11 - Mockito Tips - Verify method calls 00:06:40
- Step 12 - Mockito Tips - Argument Capture 00:04:04
- Step 13 - Mockito Tips - Argument Capture on Multiple Calls 00:02:33
- Step 14 - Introduction to Spy 00:07:42
- Step 15 - Mockito FAQ 00:03:24
- Chapter 3 : Unit Testing With Spring Boot and Mockito
- Step 00 - Section Introduction - Unit Testing with Spring Boot and Mockito 00:02:46
- Step 01 - Creating a Hello World Controller 00:03:40
- Step 02 - Using Mock Mvc to test Hello World Controller 00:12:40
- Step 03 - Using Response Matchers to check status and content 00:05:07
- Step 04 - Creating a Basic REST Service in Item Controller 00:05:08
- Step 05 - Unit Testing Item Controller and Basic JSON Assertions 00:04:05
- Step 06 - Digging deeper into JSON Assert 00:12:26
- Step 07 - Writing a REST Service talking to Business Layer 00:04:10
- Step 08 - Writing Unit Test for REST Service mocking Business Layer 00:06:51
- Step 09 - 00 - Overview of Steps 09 to 15 00:01:41
- Step 09 - 01 - Prepare Data Layers with JPA, Hibernate and H2 00:03:24
- Step 10 - Create Item Entity and Populate data with data.sql 00:06:00
- Step 11 - Create a RESTful Service talking to the database 00:07:54
- Step 12 - Writing Unit Test for Web Layer - Controller - Using Mock MVC 00:06:11
- Step 13 - Exercise & Solution - Writing Unit Test for Business Layer – Mocking 00:05:27
- Step 14 - Writing Unit Test for Data Layer - Data JPA Test 00:08:01
- Step 15 - Writing an Integration Test using @SpringBootTest 00:08:51
- Step 16 - Tip - Using @MockBean to mock out dependencies you do not want to talk 00:05:03
- Step 17 - Tip - Creating Different Test Configuration 00:03:40
- Step 18 - Writing Unit Tests for Other Request Methods 00:03:28
- Step 19 - Refactor SomeBusinessImpl to use Functional Programming 00:03:49
- Step 20 - Better Assertions with Hamcrest – HamcrestMatcherTest 00:08:37
- Step 21 - Better Assertions with AssertJ – AssertJTest 00:06:27
- Step 22 - Better Assertions with JSONPath – JSONPathTest 00:09:38
- Step 23 - Tip Patterns – xunitpatterns 00:01:22
- Step 24 - Tip - Measuring Test Coverage with Eclipse 00:04:25
- Step 25 - Tip - Keep an eye on performance of unit tests! 00:03:03
- Step 26 - Good Unit Tests 00:05:34
- Chapter 4 : Congratulations
Show and hide more