Skip to content

Conversation

@thorlauridsen
Copy link
Owner

@thorlauridsen thorlauridsen commented Nov 29, 2025

Testcontainers allow us to spin up a temporary Docker image during tests. For this project, we will spin up a temporary PostgreSQL database to run the controller tests against a real PostgreSQL database instead of an in-memory H2 database. There are differences between PostgreSQL and H2 databases so if you plan to use a PostgreSQL database in production, it also makes sense to mimic this by using a PostgreSQL database in the tests. H2 databases are useful for quickly testing and running the system locally, but it is better to use Testcontainers to run a real PostgreSQL database for the controller tests.

Use Testcontainers for controller tests:

  • Add Testcontainers annotation in controller tests.
  • Define a PostgreSQLContainer which will be used for the tests.
  • Add application-postgres.yml with connection settings for PostgreSQL.
  • Add ActiveProfiles("postgres") annotation in controller test which ensures it uses application-postgres.yml.
  • Update README.md.

@thorlauridsen thorlauridsen self-assigned this Nov 29, 2025
@thorlauridsen thorlauridsen added the enhancement New feature or request label Nov 29, 2025
@thorlauridsen thorlauridsen merged commit 145ccd7 into main Nov 29, 2025
1 check passed
@thorlauridsen thorlauridsen deleted the use-testcontainers branch November 29, 2025 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants