Проблема в следующем:
Когда я пытаюсь использовать singleton-testcontainer, все мои тестовые классы после первого проваливаются из-за утверждений.
Это означает, что даже если я вижу в журнале, что мои сценарии завершились успешно, Утверждения всегда терпели неудачу.
Дело в том, что когда я использую аннотацию @Testcontainers и @Container — все хорошо.
Мой первый тестовый класс.< /p>
Код: Выделить всё
@SpringBootTest(classes = {ContractSpringBootApplication.class})
@ExtendWith({MockitoExtension.class, OutputCaptureExtension.class})
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@ActiveProfiles("test")
public class UpdateMergeTest extends AbstractTestcontainersTest {
@SpyBean
@Autowired
private TechMergeUpdateRepo techMergeUpdateRepo;
@BeforeEach
void clean() {
techMergeUpdateRepo.deleteAll();
}
Код: Выделить всё
@SpringBootTest(classes = {ContractSpringBootApplication.class})
@ExtendWith({MockitoExtension.class, OutputCaptureExtension.class})
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@ActiveProfiles("test")
public class UpdateEntityTest extends AbstractTestcontainersTest {
@SpyBean
@Autowired
private TechMergeUpdateRepo techMergeUpdateRepo;
@SpyBean
@Autowired
private UpdateEntityRepo updateEntityRepo;
@BeforeEach
void clean() {
techMergeUpdateRepo.deleteAll();
updateEntityRepo.deleteAll();
}
Код: Выделить всё
public abstract class AbstractTestcontainersTest {
private final static String DATABASE_NAME = "test_name";
public static final PostgreSQLContainer postgresContainer = new PostgreSQLContainer("postgres:12")
.withReuse(true)
.withDatabaseName(DATABASE_NAME);
static {
postgresContainer.start();
}
@DynamicPropertySource
public static void overrideProps(DynamicPropertyRegistry registry) {
registry.add("spring.datasource.url", postgresContainer::getJdbcUrl);
registry.add("spring.datasource.username", postgresContainer::getUsername);
registry.add("spring.datasource.password", postgresContainer::getPassword);
registry.add("spring.datasource.driver-class-name", postgresContainer::getDriverClassName);
}
}
введите сюда описание изображения
НО!
Если я изменю свой AbstractTestcontainersTest на:
Код: Выделить всё
@Slf4j
@Testcontainers
public abstract class AbstractTestcontainersTest {
private final static String DATABASE_NAME = "test_name";
@Container
public static final PostgreSQLContainer postgresContainer = new PostgreSQLContainer("postgres:12")
.withReuse(true)
.withDatabaseName(DATABASE_NAME);
static {
postgresContainer.start();
}
@DynamicPropertySource
public static void overrideProps(DynamicPropertyRegistry registry) {
registry.add("spring.datasource.url", postgresContainer::getJdbcUrl);
registry.add("spring.datasource.username", postgresContainer::getUsername);
registry.add("spring.datasource.password", postgresContainer::getPassword);
registry.add("spring.datasource.driver-class-name", postgresContainer::getDriverClassName);
}
}
enter image description here
I checked the log output.
The feeling is that the problem is somewhere in the “underrun” of Spring tests, in test classes, starting from the second.
I checked the logs - my “scenarion” is fully completed and works correctly, but the assertions are falling
I checked the log output.
The feeling is that the problem is somewhere in the “underrun” of Spring tests, in test classes, starting from the second.
Источник: https://stackoverflow.com/questions/781 ... -always-fa