From the course: Advanced Spring: Effective Integration Testing with Spring Boot

Why bother testing?

From the course: Advanced Spring: Effective Integration Testing with Spring Boot

Start my 1-month free trial

Why bother testing?

- [Narrator] Spring Boot applications are built in multiple layers data, service and web. In unit testing, we test each of these layers independently. For example, we test the web controllers that mock out the business services. But how do we test to ensure all these layers work well when combined together? How do we test other web controller responsibilities such as input validation or exception handling? Or how do we test integrations with external systems such as database custom queries or using external API? This is where integration tests come into play. Before we start into integration tests with Spring Boot let's define what sets an integration test apart from a unit test. A unit test targets a small unit of code for example, a method or a class. Any dependencies are removed from unit tests like replacing the dependency with a test implementation or a mock object created by test framework. An integration test on the other hand can be anything of the following, a test that covers multiple units because it tests the interaction between two or more components which is spring we refer to spring beans. A test that covers multiple layers. This is actually a specialization of the first case and might cover the interaction between a web controller and a service layer or a business service, and a persistence layer. A test that covers the whole path for the application. In this test, we send the request to the application and check that it responds correctly and has changed the database state according to our expectations. A test that requires an interaction with external systems such as database SFTP server, other API endpoints. So whenever we are moving beyond unit testing and start integration testing, we should use SpringBootTest support to create an application context containing all the objects we need for all the above test types. As you progress through the course we will explore SpringBootTest libraries. Learn some three key real world testing scenarios such as testing with real database, testing service layer with caching support, web layers and testing in micro serviced environment.

Contents