Testcontainers runs application dependencies such as databases, message brokers, and other services in containers during development and integration testing. It provides a programmatic alternative to manually managing dependency containers. section 2.3.1 section 2.4.3
A typical Testcontainers workflow connects dependency startup with the application or test lifecycle:
- Start the required dependency automatically when the application starts or tests run. section 2.3.1 section 2.4.4
- Run application requests or tests against the real containerized dependency. section 2.3.1 section 2.4.3
- Use dynamically allocated ports to reduce conflicts across test environments. section 2.4.3
Spring Boot appointments service
A Java Appointments service depends on PostgreSQL. Running Gradle's bootRun starts the application and its PostgreSQL container automatically; Spring Boot likewise starts the container when tests run. The tests then exercise persistence without a separately managed database. section 2.3.1 section 2.4.3 section 2.4.4
./gradlew bootRun
Run the Java application with Gradle and trigger the dependency-container startup flow. section 2.3.1





