Skip to content

Testcontainers

Framework: Testcontainers 1.20.4

Contenedores Soportados

ContenedorImagenPuertoPropósito
PostgreSQLpostgres:17.25432Base de datos
Kafkaconfluentinc/cp-kafka:7.8.19092/9093Mensajería
Schema Registrycp-schema-registry:7.8.18081Avro
Wiremockwiremock/wiremock:3.11.08080Mock HTTP

Estructura de ContainerConfigs

ContainerConfig (interface)
     └── MultiContainerConfig extends ContainerConfig
          └── KafkaContainerCustomConfig (abstract)
          └── ConfluentKafkaContainerCustomConfig (class)
       └── WiremockContainerCustomConfig (abstract)

Uso

java
@TestConfiguration
public class PostgresContainerCustomConfig extends BaseContainerCustomConfig
    implements ContainerConfig {

    @Bean
    @ServiceConnection
    PostgreSQLContainer<?> postgresContainer() {
        return new PostgreSQLContainer<>("postgres:17.2")
            .withNetwork(Network.newNetwork())
            .withNetworkAliases("postgres")
            .withDatabaseName("postgres")
            .withUsername("sa")
            .withPassword("sa");
     }
}

Released under the MIT License.