Open ku-kim opened 2 years ago
# build.gradle
dependencies {
// ...
// TestContainers
testImplementation 'org.testcontainers:junit-jupiter:1.17.4'
}
# ./src/test/resources/logback-test.xml
## ref : https://www.testcontainers.org/supported_docker_environment/logging_config/
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern>
</encoder>
</appender>
<root level="info">
<appender-ref ref="STDOUT"/>
</root>
<logger name="org.testcontainers" level="INFO"/>
<logger name="com.github.dockerjava" level="WARN"/>
<logger name="com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.wire" level="OFF"/>
</configuration>
// ./test/java/com/example/redis/RedisContainerTest.java
@Testcontainers
class RedisTestContaners {
@Container
public GenericContainer redis = new GenericContainer("redis:7.0.5")
.withExposedPorts(6379);
@Test
void testContainers_실행확인() {
assertThat(redis.getHost()).isEqualTo("localhost");
assertThat(redis.getExposedPorts()).contains(6379);
}
}
📝 구현 목록
💡 참고자료