16 Mayıs 2020 Cumartesi

SpringTest @DynamicPropertySource Anotasyonu

Giriş
Açıklaması şöyle.
In contrast to the @TestPropertySource annotation that is applied at the class level, @DynamicPropertySource must be applied to a static method that accepts a single DynamicPropertyRegistry argument which is used to add name-value pairs to the Environment. Values are dynamic and provided via a Supplier which is only invoked when the property is resolved.
Örnek
Şöyle yaparız
@SpringBootTest
@Testcontainers
class ExampleIntegrationTests {

  @Container
  static Neo4jContainer<?> neo4j = new Neo4jContainer<>();

  @DynamicPropertySource
  static void neo4jProperties(DynamicPropertyRegistry registry) {
    registry.add("spring.data.neo4j.uri", neo4j::getBoltUrl);
  }

}

Hiç yorum yok:

Yorum Gönder