16 Testing Spring applications

 

This chapter covers

  • Understanding dependency injection
  • Building and testing a Spring application
  • Using SpringExtension for JUnit Jupiter
  • Testing Spring application features with JUnit 5

“Dependency Injection” is a 25-dollar term for a 5-cent concept.

--James Shore

Spring is a lightweight--but at the same time flexible and universal--open source set of frameworks for creating Java applications. It is not dedicated to any particular layer, which means it can be used at the level of any layer of a Java application. This chapter will focus on the basis of Spring: the dependency injection (or inversion of control) pattern; and how to test core Spring applications with the help of JUnit 5.

16.1 Introducing the Spring Framework

A library is a collection of classes or functions that enables code reuse: we can use code created by other developers. Usually, a library is dedicated to a domain-specific area. For example, there are libraries of computer graphics that let us quickly build three-dimensional scenes and display them on the computer screen.

16.2 Introducing dependency injection

16.3 Using and testing a Spring application

16.3.1 Creating the Spring context programmatically

16.3.2 Using the Spring TestContext framework

16.4 Using SpringExtension for JUnit Jupiter

16.5 Adding a new feature and testing it with JUnit 5

Summary