You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Use Testcontainers for controller tests (#60)
[Testcontainers](https://github.com/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 Gradle dependencies to `local.versions.toml` and `api/build.gradle.kts`:
- `org.springframework.boot:spring-boot-testcontainers`
- `org.testcontainers:postgresql `
- Add `TestContainerConfig` which defines the PostgreSQL container and database settings.
- Add annotations `@Import(TestContainerConfig.class)` and `@ActiveProfiles("postgres")` to `CustomerControllerTest` to ensure that a PostgreSQL database is used for the tests.
- Add `application-postgres.yml` with connection settings for PostgreSQL.
- Update `README.md`.
0 commit comments