Testing

Testing

Software change is unavoidable. Software must adapt to changes in the business and in technology. But not everything changes all the time and at the same time. That’s why it’s important to ensure that stable parts do not regress.

In a Maven or Gradle project, tests are located in the src/test/java directory.

For writing tests, Spring Boot relies on a set of libraries. In this course, we will experiment with JUnit 5, AssertJ, and Mockito.

  • Unit tests, which test the functionality of a module (e.g., a class), replacing external dependencies (databases, message queues, web services, etc.) with stubs if necessary.

  • Integration tests, which verify the integration of the functionality with the external services on which it depends.

  • End-to-end tests, which verify that the application responds correctly to a business scenario. These tests often take a long time to run and tend to be reserved for essential nominal scenarios.

As a first step, to measure the relative effort we will spend on these different types of tests, we will use the classic test pyramid, with a broad base of unit tests and few end-to-end tests.

Testing Pyramid cropped

These tools are not the only ones available to us. We can use Golden Master Testing or Approvaltests. Several code katas allow you to learn these, for example Gilded Rose and Ugly Trivia.

Tests can also be written to enforce standards, for example software architecture rules with ArchUnit.