13 Haziran 2023 Salı

SpringTest Testcontainers @ServiceConnection

Giriş
Şu satırı dahil ederiz
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
Açıklaması şöyle
The @ServiceConnection removes the need to write @DynamicPropertySource property overrides.
Örnek
Şöyle yaparız
@SpringBootTest
public class ServiceConnectionFieldTest {

  @Container
  @ServiceConnection
  static PostgreSQLContainer postgres = new PostgreSQLContainer(DockerImageName.parse("postgres:15.1"))
      .withUsername("testUser")
      .withPassword("testSecret")
      .withDatabaseName("testDatabase");

  @BeforeAll
  static void setup(){
    postgres.start();
  }
  ...
}
@RestartScope Anotasyonu
Giriş
Şu satırı dahil ederiz
import org.springframework.boot.devtools.restart.RestartScope;
Örnek - 
Açıklaması şöyle
annotation which prevents the container restarts during automatic reloads by Spring Boot DevTools.

Hiç yorum yok:

Yorum Gönder