Complete the code to start a PostgreSQL test container.
PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>("[1]:latest"); postgres.start();
The correct Docker image name for PostgreSQL test container is postgres:latest.
Complete the code to get the JDBC URL from the running container.
String jdbcUrl = postgres.[1]();The method to get the JDBC URL from a PostgreSQLContainer is getJdbcUrl().
Fix the error in the annotation to use Testcontainers with JUnit 5.
@[1] public class MyDatabaseTest { // test code }
For JUnit 5, use @ExtendWith(TestcontainersExtension.class) to enable Testcontainers support.
Fill both blanks to define a Spring Boot test configuration that uses the container's JDBC URL and credentials.
@DynamicPropertySource
static void datasourceProperties(DynamicPropertyRegistry registry) {
registry.add("spring.datasource.url", () -> [1]);
registry.add("spring.datasource.username", () -> [2]);
}Use getJdbcUrl() for the datasource URL and getUsername() for the username from the container.
Fill all three blanks to create a Map of properties for Spring Boot datasource configuration using the container.
Map<String, String> props = Map.of(
"spring.datasource.url", [1],
"spring.datasource.username", [2],
"spring.datasource.password", [3]
);Use getJdbcUrl(), getUsername(), and getPassword() from the container to configure Spring Boot datasource properties.