Skip to content

Commit

Permalink
[feat] 테스트를 위한 embedded redis 를 구동시키기 위한 extension 설정
Browse files Browse the repository at this point in the history
- JUnit 테스트를 실행할 때 extension을 detect할 수 있도록 기능 추가
  • Loading branch information
Hyeon-Uk committed Aug 27, 2024
1 parent d4f046c commit 6eae4b7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/test/java/camp/woowak/lab/helper/EmbeddedRedisExtension.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package camp.woowak.lab.helper;

import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;

import redis.embedded.RedisServer;

public class EmbeddedRedisExtension implements BeforeAllCallback {

private static RedisServer redisServer;
private static final ExtensionContext.Namespace NAMESPACE = ExtensionContext.Namespace.create(
EmbeddedRedisExtension.class);

@Override
public void beforeAll(ExtensionContext context) throws Exception {
if (redisServer == null) {
redisServer = new RedisServer(6379);
redisServer.start();
context.getRoot().getStore(NAMESPACE).put("redisServer", redisServer);
}
}

@DynamicPropertySource
static void redisProperties(DynamicPropertyRegistry registry) {
registry.add("spring.data.redis.host", () -> "localhost");
registry.add("spring.data.redis.port", () -> "6379");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
camp.woowak.lab.helper.EmbeddedRedisExtension
2 changes: 2 additions & 0 deletions src/test/resources/junit-platform.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
junit.jupiter.extensions.autodetection.enabled=true
junit.jupiter.extensions.autodetection.classpath.enabled=true

0 comments on commit 6eae4b7

Please sign in to comment.