-
Notifications
You must be signed in to change notification settings - Fork 0
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
테스트 컨테이너 학습하기 #2
Comments
1. 테스트 컨테이너의 편리한 경우
테스트 컨테이너의 단점
JDBC 를 사용한다면 간단히 설정 가능spring:
datasource:
url: jdbc:tc:mysql:8:///soolsul?TC_REUSABLE=true
username: test
password: test121212
driver-class-name: org.testcontainers.jdbc.ContainerDatabaseDriver Redis의 경우, 별도로 만들어줘야 함.public abstract class TestRedisContainer {
private static final String DOCKER_REDIS_IMAGE = "redis:7.0.5-alpine";
public static GenericContainer REDIS_CONTAINER =
new GenericContainer<>(DockerImageName.parse(DOCKER_REDIS_IMAGE))
.withExposedPorts(6379)
.withReuse(true);
static {
REDIS_CONTAINER.start();
System.setProperty("spring.redis.host", REDIS_CONTAINER.getHost());
System.setProperty("spring.redis.port", REDIS_CONTAINER.getMappedPort(6379).toString());
}
} |
JUnit 5 Quickstart1. 테스트 컨테이너가 없을 떄의 문제점
1. Add Testcontainers as a test-scoped dependency
testImplementation "org.junit.jupiter:junit-jupiter:5.8.1"
testImplementation "org.testcontainers:testcontainers:1.17.6"
testImplementation "org.testcontainers:junit-jupiter:1.17.6" 2. Get Testcontainers to run a Redis container during our tests@Container
public GenericContainer redis = new GenericContainer(DockerImageName.parse("redis:5.0.3-alpine"))
.withExposedPorts(6379);
3. Make sure our code can talk to the container
@Testcontainers
public class RedisBackedCacheIntTest {
private RedisBackedCache underTest;
// container {
@Container
public GenericContainer redis = new GenericContainer(DockerImageName.parse("redis:5.0.3-alpine"))
.withExposedPorts(6379);
// }
@BeforeEach
public void setUp() {
String address = redis.getHost();
Integer port = redis.getFirstMappedPort();
// Now we have an address and port for Redis, no matter where it is running
underTest = new RedisBackedCache(address, port);
}
@Test
public void testSimplePutAndGet() {
underTest.put("test", "example");
String retrieved = underTest.get("test");
assertThat(retrieved).isEqualTo("example");
}
} |
사이드 리뷰 피드백1. @DynamicPropertySource(참고 레퍼런스 : https://recordsoflife.tistory.com/607)
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
참고 내용
The text was updated successfully, but these errors were encountered: