28 Ağustos 2021 Cumartesi

SpringTest Testcontainers @TestContainers Anotasyonu

(disabledWithoutDocker Alanı
Örnek
Şöyle yaparız
@SpringBootTest
@TestContainers(disabledWithoutDocker = true)
@ContextConfiguration(initializers = ExampleIntegrationTests.Initializer.class)
class ExampleIntegrationTests {
  @Container
  public static CassandraContainer<?> cassandra = new CassandraContainer<>();
  
  static class Initializer 
    implements ApplicationContextInitializer<ConfigurableApplicationContext> {
    @Override
    public void initialize(ConfigurableApplicationContext context) {
      int cqlPort = cassandra.getMappedPort(CassandraContainer.CQL_PORT);
      TestPropertyValues.of("spring.data.cassandra.port="+ cqlPort)
        .applyTo(context.getEnvironment());
    }
  }
}

Hiç yorum yok:

Yorum Gönder