-
Notifications
You must be signed in to change notification settings - Fork 40.8k
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
Testcontainers @DynamicPropertySource and @Container execution order doesn't work properly #40937
Comments
You can try annotating But it will trigger another problem, the
Here is the test case: package com.example.demo;
import org.junit.jupiter.api.Test;
import org.springframework.boot.testcontainers.context.ImportTestcontainers;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
@SpringJUnitConfig
//@Testcontainers
public class TestContainerTests {
@Container
static PostgreSQLContainer<?> container = new PostgreSQLContainer<>("postgres");
@DynamicPropertySource
static void populateDynamicPropertyRegistry(DynamicPropertyRegistry registry) {
System.out.println(container.getMappedPort(5432));
}
@Test
void test() {
}
@Configuration
@ImportTestcontainers(TestContainerTests.class)
static class Config {
}
} |
The problem is that you're accessing the container directly within your
This requires the container to have been started when the This worked in 3.2.0 as the containers were started very early but that was at the expense of support for parallel startup being broken. This was fixed in #38831. In summary, this only worked in 3.2.0 accidentally and, unfortunately, you'll have to make some changes to adapt to the way things now work. You can either remove |
Hey team, we have met an issue when we use spring-boot-testcontainers 3.3.0.
The Problem:
How to reproduce it:
demo-project.zip
Please us the demo-project and directly run
RunApplicationLocally.kt
What we have found:
If we use spring-boot-testcontainers 3.2.0, all good.
If we use spring-boot-testcontainers 3.2.1 or later versions, it fails.
Could you help us fix it up or any other way we could work it around?
The text was updated successfully, but these errors were encountered: