Skip to content

Latest commit

 

History

History
35 lines (30 loc) · 1.09 KB

template test integratation avec testcontainers.md

File metadata and controls

35 lines (30 loc) · 1.09 KB

template de test d'intégration avec testcontainers

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@Testcontainers
class DatabaseFilmVuRepositoryTest {
    @Inject
    private DatabaseRepository databaseRepository;

    @Container
    static PostgreSQLContainer<?> postgreSQLContainer =
        new PostgreSQLContainer<>("postgres:14-alpine")
            .withCopyFileToContainer(
                MountableFile.forClasspathResource("/docker_postgres_init.sql"),
                "/docker-entrypoint-initdb.d/"
            );

    @DynamicPropertySource
    static void registerMySQLProperties(DynamicPropertyRegistry registry) {
        registry.add("spring.datasource.url", postgreSQLContainer::getJdbcUrl);
        registry.add("spring.datasource.username", postgreSQLContainer::getUsername);
        registry.add("spring.datasource.password", postgreSQLContainer::getPassword);
    }

    @Test
    public void mon_test() {
        // given

        // when
        var result = databaseRepository.fetch();

        // then
        assertThat(result).isEqualTo();
    }
}