PostgreSQL integration tests with Testcontainers
When developing tests for a component, one of the biggest challenges is managing dependent services like databases. While creating mocks or using an in-memory database like H2 can be a solution, these approaches may hide potential issues in our application. Testcontainers is an open-source framework that offers temporary instances of popular databases and other services that can be run on Docker containers. This provides a more reliable way to test applications.
In this recipe, you will learn how to create an integration test that depends on PostgreSQL using Testcontainers.
Getting ready
In this recipe, we’ll create some tests for the application created in the previous recipe, Creating the database schema from our code. I prepared a working version as a starting point for this recipe in case you haven’t completed the previous recipe yet. You can find it in the book’s GitHub repository at https://github...