Master Java Unit Testing with Spring Boot and Mockito [Video]

More Information
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
About

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.

Style and Approach

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

Features
  • Learn 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.
Course Length 3 hours 55 minites
ISBN 9781789346077
Date Of Publication 24 May 2018
Step 00 - Section Introduction - Unit Testing 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 - 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 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
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

Authors

Ranga Karanam

Ranga Karanam of in28Minutes fame is an architect with 15 years of Java programming and design experience with major banking clients across the world. He started in28Minutes with the aim of creating hands-on courses with real-world projects. The Step-By-Step series of courses is one of his creations. They use a problems-solution based step-by-step approach with practical, and real-world application examples. While their primary expertise is in the development, design, and architecture of Java and related frameworks (Spring, Spring Boot, Spring MVC, Struts, Hibernate), they are expanding into the front-end world (Bootstrap, JQuery, Angular JS). The foundations for building high-quality applications are best laid down while learning. They love open source and therefore, all their code is open source too and available on Github. They use the 80-20 rule, touching upon other things to briefly equip you with enough knowledge to find out more on your own.