Starter Package
The starter package helps you to learn all the skills you need when you are writing unit tests for Spring web applications. This package consists of seven topics:
The Introduction to JUnit 4 topic acts as an introduction to the other lessons of this course. During this topic you will write your first test methods, and add both setup and teardown methods to your test class. Also, you will learn to use both JUnit 4 test runners and JUnit 4 rules.
The Creating Test Data topic helps you to save time by writing less object creation code. You will learn to create test data by using the new
keyword, factory methods, and test data builders. After you have completed this topic, you will understand the pros and cons of each technique, and you can use these techniques for emphasizing the essential properties of the created objects. In other words, you can write tests which are easy to read, write, and maintain.
The Writing Assertions topic describes how you can write assertions which emphasize the purpose of the assertion. You will learn to write assertions by using the JUnit 4 assertion API, Hamcrest, and AssertJ. After you have completed this topic, you can write less assertion code and use these tools for writing assertions which are easy to read, write, and maintain.
The Introduction to Test Doubles topic helps you to understand how stubs, mocks, fakes, dummies, and spies work. After you have completed this topic, you understand that a mock isn’t the only test double and you can select the best tool for the job.
The Creating Test Doubles With Mockito topic describes how you can create different test doubles with Mockito, emphasize the purpose of the created test doubles, and use these test doubles in your unit tests. Finally, you will learn how you can eliminate boilerplate code by using lambda expressions.
The Introduction to Unit Testing topic provides the information you need when you start writing unit tests for real applications. This topic helps you to understand why you should write nested unit tests, describes how you can write them, and identifies five best practices of nested unit tests. Also, you will learn why you should use the JUnitParams library when you are writing parameterized tests with JUnit 4. Finally, this topic also describes how you can run your unit tests with Maven and Gradle.
After you have completed this topic, you understand how you can make your tests easier to write and maintain by putting your setup code to the right place, and you know how you can make your tests easier to read by transforming them into well-structured specifications. In other words, this topic will help you to save time by writing less test code.
The Writing Unit Tests for Spring Web Applications topic helps you to write fast unit tests which test the “full” Spring MVC runtime behaviour. In other words, this topic describes how you can write tests for both routing and validation logic. Also, you will learn to write assertions for the HTTP request send to the system under test and ensure that system under test returns the expected HTTP response.
After you have completed this topic, you understand how you can configure the system under test and you can write unit tests for both normal Spring MVC controllers and Spring MVC REST APIs.
Package Content
Creating Test Data
-
Introduction to System Under Test
-
Creating Test Data With the New Keyword: The Telescoping Constructor (Anti)Pattern
-
Creating Test Data With the New Keyword: The JavaBeans Style Construction
-
Introduction to Factory Methods
-
Creating Test Data With Factory Methods: Using Local Factory Methods
-
Creating Test Data With Factory Methods: Using an Object Mother Class
-
Creating Our First Test Data Builder
-
Creating Stateful Objects With Test Data Builders
-
Overriding a Builder With a Test Data Builder
-
Emphasizing the State of the Created Object
- Introduction to System Under Test
- Creating Test Data With the New Keyword: The Telescoping Constructor (Anti)Pattern
- Creating Test Data With the New Keyword: The JavaBeans Style Construction
- Introduction to Factory Methods
- Creating Test Data With Factory Methods: Using Local Factory Methods
- Creating Test Data With Factory Methods: Using an Object Mother Class
- Creating Our First Test Data Builder
- Creating Stateful Objects With Test Data Builders
- Overriding a Builder With a Test Data Builder
- Emphasizing the State of the Created Object
Writing Unit Tests for Spring Web Applications
-
Introduction to Spring MVC Test Framework
-
Configuring the System Under Test
-
Writing Unit Tests for “Normal” Controllers – Configuration
-
Writing Unit Tests for “Normal” Controllers – Rendering Data
-
Writing Unit Tests for “Normal” Controllers – Forms
-
Writing Unit Tests for a REST API – Configuration
-
Writing Unit Tests for a REST API – Reading Data
-
Writing Unit Tests for a REST API – Writing Data
- Introduction to Spring MVC Test Framework
- Configuring the System Under Test
- Writing Unit Tests for “Normal” Controllers – Configuration
- Writing Unit Tests for “Normal” Controllers – Rendering Data
- Writing Unit Tests for “Normal” Controllers – Forms
- Writing Unit Tests for a REST API – Configuration
- Writing Unit Tests for a REST API – Reading Data
- Writing Unit Tests for a REST API – Writing Data