Skip to content

Commit ec2a46c

Browse files
BENCH-187-TESTCONTAINERS Created an abstract ContainerisedTest for any ITs to extend
1 parent c680d17 commit ec2a46c

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.answerdigital.answerking.utility;
2+
3+
import org.junit.jupiter.api.AfterAll;
4+
import org.junit.jupiter.api.BeforeAll;
5+
import org.springframework.test.context.ActiveProfiles;
6+
import org.springframework.test.context.DynamicPropertyRegistry;
7+
import org.springframework.test.context.DynamicPropertySource;
8+
import org.testcontainers.containers.MySQLContainer;
9+
10+
@ActiveProfiles("test")
11+
public abstract class ContainerisedTest {
12+
private static final MySQLContainer container =
13+
new MySQLContainer<>("mysql:8.0.31")
14+
.withDatabaseName("answer_king_test")
15+
.withUsername("test_user")
16+
.withPassword("GS3ef_fsd^!")
17+
.withReuse(true);
18+
19+
@BeforeAll
20+
public static void startup() {
21+
container.start();
22+
}
23+
24+
@AfterAll
25+
public static void shutdown() {
26+
container.stop();
27+
}
28+
29+
@DynamicPropertySource
30+
private static void overrideProps(DynamicPropertyRegistry registry) {
31+
registry.add("spring.datasource.url", container::getJdbcUrl);
32+
}
33+
}

0 commit comments

Comments
 (0)