Skip to content

@DataJpaTest test slice doesn't working with container created in @TestConfiguration #36239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
piotrooo opened this issue Jul 5, 2023 · 1 comment
Labels
status: duplicate A duplicate of another issue

Comments

@piotrooo
Copy link

piotrooo commented Jul 5, 2023

For the following containers configuration:

@TestConfiguration(proxyBeanMethods = false)
public class ContainersConfiguration {
    @Bean
    @ServiceConnection
    @RestartScope
    PostgreSQLContainer<?> postgresContainer() {
        return new PostgreSQLContainer<>("postgres:13");
    }

    @Bean
    @ServiceConnection
    @RestartScope
    RabbitMQContainer rabbitContainer() {
        return new RabbitMQContainer("rabbitmq:3.11");
    }
}

When I try to use it in the repository tests (which are using a slice test annotation @DataJpaTest) containers aren't reused and configured correctly.

@DataJpaTest
@Testcontainers
@Import(ContainersConfiguration.class)
@AutoConfigureTestDatabase(replace = NONE)
class RepositoryItTest {
    // tests
}

Declare properties in the @DataJpaTest works (creates only slice of the context without rabbit), but that seems to be a duplication.

@DataJpaTest(properties = {
        "spring.datasource.url=jdbc:p6spy:tc:postgresql:13://service-test"
})
@Testcontainers
@AutoConfigureTestDatabase(replace = NONE)
class RepositoryItTest {
}

Using an annotation @SpringBootTest, make this test working but it's create a whole context, which containers (rabbit) which aren't necessary for run them.

@SpringBootTest(webEnvironment = RANDOM_PORT)
@Testcontainers
@Import(ContainersConfiguration.class)
@AutoConfigureTestDatabase(replace = NONE)
class RepositoryItTest {
    // tests
}

Spring Boot: 3.1.1

Possible related with #35253.

@piotrooo piotrooo changed the title @DataJpaTest test slice doesn't worki with container created in @TestConfiguration @DataJpaTest test slice doesn't working with container created in @TestConfiguration Jul 5, 2023
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 5, 2023
@wilkinsona
Copy link
Member

Thanks for the report. I am pretty sure that this is a duplicate of #35252.

@wilkinsona wilkinsona closed this as not planned Won't fix, can't repro, duplicate, stale Jul 5, 2023
@wilkinsona wilkinsona added status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged labels Jul 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

3 participants