liveBook · Manning

Spring

As explained in Testing Spring Boot Applications

Spring Framework is a modular Java framework that provides an application programming model based on dependency injection, configuration, and related infrastructure abstractions.

Spring provides a modular Java application model built around declarative configuration, dependency injection, and infrastructure abstractions. Its ApplicationContext discovers, creates, and exposes application components as beans, avoiding imperative wiring between classes. section 1.3 section 1.0

Spring Boot applies Spring conventions to reduce configuration, especially for testing:

  • Detects dependencies such as spring-boot-starter-webmvc and starts a web server on port 8080. section 1.0
  • Creates and connects testing utilities such as MockMvcTester to the application context. section 1.0
  • Provides familiar annotations such as @Autowired and @TestConfiguration for test-specific component wiring. section 1.0
  • Trades manual control for convenience; broad Spring contexts can add configuration complexity and affect test-suite speed. section 1.3 section 1.0

Replacing an external dependency in a test application

A test configuration can scan the application while excluding the production WidgetValidator, load test.properties, and register a StubWidgetValidator bean instead. Tests can then exercise the remaining application components without running the external service. section 1.3

Figure 1.3 The architecture of the application we would like to test. Arrows represent the data flowing through the system. The WidgetValidator cannot be used in tests, and needs to be replaced by a stub.
ch01 f03 garniermoiroux

Use the architecture diagram to trace the controller, repository, and external validator, then identify the dependency that tests replace with a stub. section 1.3

How Testing Spring Boot Applications covers it

How deep it goes
Explains dependency wiring, bean access, Boot conventions, and test configuration, but stops short of broader framework internals.
Examples
Uses a Widget REST controller, repository, external validator, stub replacement, and Spring test configuration.
What it assumes
Assumes familiarity with application components and HTTP testing while introducing declarative wiring and Spring-specific test annotations.
What you can do after
Configure a Spring test application, replace selected components, and exercise application beans through the context.
How it connects
Connects dependency injection, annotations, Spring ApplicationContext, Spring Boot, convention over configuration, and testing.

Also explained in

Compare how 5 books explain Spring →

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.