Skip to content

Commit 4717c1b

Browse files
committed
This should do the trick. 3
1 parent fdb53d2 commit 4717c1b

2 files changed

Lines changed: 29 additions & 4 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.springqprobackend.springqpro.testcontainers;
2+
3+
import org.testcontainers.containers.GenericContainer;
4+
import org.testcontainers.containers.PostgreSQLContainer;
5+
import org.testcontainers.containers.wait.strategy.Wait;
6+
import org.testcontainers.junit.jupiter.Testcontainers;
7+
8+
@Testcontainers
9+
public abstract class ContainerTestBase {
10+
11+
protected static final PostgreSQLContainer<?> POSTGRES =
12+
new PostgreSQLContainer<>("postgres:18")
13+
.withDatabaseName("springqpro")
14+
.withUsername("springqpro")
15+
.withPassword("springqpro");
16+
17+
protected static final GenericContainer<?> REDIS =
18+
new GenericContainer<>("redis:7-alpine")
19+
.withExposedPorts(6379)
20+
.waitingFor(Wait.forListeningPort());
21+
22+
static {
23+
POSTGRES.start();
24+
REDIS.start();
25+
}
26+
}

springqpro-backend/src/test/java/com/springqprobackend/springqpro/testcontainers/IntegrationTestBase.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,14 @@
2323
*/
2424
//public abstract class IntegrationTestBase extends BasePostgresContainer {
2525
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = "spring.main.allow-bean-definition-overriding=true")
26-
@Testcontainers
2726
@ActiveProfiles("test")
2827
@Sql(
2928
scripts = "/cleanup.sql",
3029
executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD
3130
)
32-
public abstract class IntegrationTestBase {
31+
public abstract class IntegrationTestBase extends ContainerTestBase {
3332

34-
@Container
33+
/*@Container
3534
static final PostgreSQLContainer<?> POSTGRES =
3635
new PostgreSQLContainer<>("postgres:18")
3736
.withDatabaseName("springqpro")
@@ -45,7 +44,7 @@ public abstract class IntegrationTestBase {
4544
new GenericContainer<>("redis:7-alpine")
4645
.withExposedPorts(6379)
4746
.withReuse(false);
48-
//.withReuse(true);
47+
//.withReuse(true);*/
4948

5049
@DynamicPropertySource
5150
static void registerDynamicProps(DynamicPropertyRegistry registry) {

0 commit comments

Comments
 (0)