liveBook · Manning

Spring-boot-starter-webmvc-test

As explained in Testing Spring Boot Applications

A Spring Boot testing starter that adds MVC-specific testing support to the core test starter.

spring-boot-starter-webmvc-test is a Spring Boot testing starter for MVC applications. It includes the core spring-boot-starter-test dependencies plus MVC-specific testing support, while remaining restricted to test code through test scope. section 1.1

Listing 1.1 The spring-boot-starter-webmvc-test dependency in the pom.xml of a typical Boot project
<dependencies>
  <!-- ... -->
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-webmvc-test</artifactId>
    <scope>test</scope> #1
  </dependency>
</dependencies>

A typical Maven dependency declaration places the starter in test scope, preventing its testing-only dependencies from entering production code. section 1.1

Use the starter according to the application’s web stack:

  • Choose webmvc-test for Spring MVC applications, typically created with the Spring Web selection and backed by a Servlet container. section 1.1
  • Choose webflux-test instead for WebFlux applications using the reactive stack. section 1.1
  • Treat the starter as declarative test infrastructure: annotations such as @SpringBootTest let Spring’s testing machinery discover configuration and manage application startup. section 1.1

How Testing Spring Boot Applications covers it

How deep it goes
Defines the starter’s contents, stack alternatives, scope, and dependency layout, but does not detail individual MVC testing classes.
Examples
Uses a Maven pom.xml dependency and a Gradle testCompileClasspath tree to show test-scoped resolution.
What it assumes
Assumes a Spring Boot application and distinguishes MVC from the alternative WebFlux web stack.
What you can do after
Build it from scratch by adding the test-scoped starter to a Spring MVC project.
How it connects
Connects Spring Boot testing with spring-boot-starter-test, Spring MVC, WebFlux, Spring Initializr, Maven, and Gradle.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Testing Spring Boot Applications. The section links point to the parts of the book it draws on.