Last updated: April 22, 2024
I started to write a new version of my Spring MVC Test tutorial. When this tutorial is finished, it describes how you can write both unit and integration tests for Spring MVC controllers by using the Spring MVC Test framework (aka Spring MockMvc) and JUnit 5. At the moment, my new Spring MVC Test tutorial consists of these blog posts:
Introduction and Unit Testing
- Introduction to Spring MVC Test Framework provides a quick introduction to Spring MVC Test framework. After you have read this blog post, you can identify the key components of the Spring MVC Test framework, and get the required dependencies with Maven and Gradle.
- The Best Way to Configure the Spring MVC Test Framework, Part One helps you to select the best way to configure the Spring MVC Test framework when you are writing unit tests.
- Writing Unit Tests for "Normal" Spring MVC Controllers: Configuration describes how you can configure the system under test by using the standalone configuration when you are writing unit tests for controller methods that render data or process form submissions.
- Writing Tests for Spring MVC Controllers: Test Case 101 provides a very quick introduction to sending HTTP requests to the system under test when you are using the Spring MVC Test framework.
- Writing Unit Tests for Spring MVC Controllers: Rendering a Single Item describes how you can write unit tests for a Spring MVC controller which renders the information of a single item.
- Writing Unit Tests for Spring MVC Controllers: Rendering a List describes how you can write unit tests for a Spring MVC controller that renders a list.
- Writing Unit Tests for Spring MVC Controllers: Forms describes how you can write unit tests for a Spring MVC controller that submits a form.
- Writing Unit Tests for a Spring MVC REST API: Configuration describes how you can configure the system under test by using the standalone configuration when you are writing unit tests for a Spring MVC REST API.
- Writing Unit Tests for a Spring MVC REST API: Returning a Single Item describes how you can write unit tests for a Spring MVC API endpoint which returns the information of a single item as JSON.
- Writing Unit Tests for a Spring MVC REST API: Returning a List describes how you can write unit tests for a Spring MVC API endpoint which returns a list as JSON.
- Writing Unit Tests for a Spring MVC REST API: Writing Data describes how you can write unit tests for a Spring MVC API endpoint which inserts data into a database and returns data as JSON.
Integration Testing
- The Best Way to Configure the Spring MVC Test Framework, Part Two helps you to select the best way to configure the Spring MVC Test framework when you are writing integration tests.
- The Best Tools for Writing Integration Tests for Spring Boot Web Applications highlights six testing tools which we should use when we are writing integration tests for Spring Boot web applications.
- Writing Integration Tests for Spring Boot Web Applications: Build Setup describes how you can keep your feedback loop as short as possible when you are writing integration tests for Spring Boot web applications and you build your project with Maven.
- Writing Integration Tests for Spring Boot Web Applications: Spring Profiles describes how you can leverage Spring profiles when you have to create a separate configuration for your integration tests.
Other
- How to Write MockMvc Tests Without ObjectMapper, Part One - The Simplest Possible Solution describes how we can build the request body that's send to the system under test if we cannot use
ObjectMapper
, we must use the simplest possible solution, and we must use Java. - How to Write MockMvc Tests Without ObjectMapper, Part Two - Using a Template Engine describes how we can build the request body that's send to the system under test if we cannot use
ObjectMapper
, we cannot hard-code the request body, and we must use Java. - How to Write MockMvc Tests Without ObjectMapper, Part Three - Should We Do It? evaluates if we should get rid of
ObjectMapper
when we are writing MockMvc tests for Spring MVC REST APIs.