Integration testing REST API with Spring Boot

Spring Boot applications are built in multiple layers—web, business, and data, for example.

In unit tests, we test each of these layers independently. For example, we test the web controllers that mock out the business services. This ensures that we can test each of these components in isolation.

But how do you test that all these layers work well when combined together?

That's where we use integration tests, launching the entire Spring context with all the layers.

Typically, in automated integration tests, you do not want to rely on external dependencies. We would typically use an in-memory database, such as H2.

Let's start with writing a simple integration test for the Hello World API.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset