Skip to content
Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

Spring Test Redis

Build Status

Tools to write integration tests of Spring Framework with Redis.


redis container scheme

How to write integration tests on Spring Framework with Redis

Add this library in dependencies:


And now, you can start Redis in docker (TestContainers) by the using of @RedisTestContainer annotation in tests:

class RedisTestContainerTest {

    private RedisTemplate redisTemplate;

    void readWriteValueByRedisTemplate() {
        String key = "test";
        String value = "sabracadabra";
        // Act
        redisTemplate.opsForValue().set(key, value);
        // Assert

You can use this annotation to start Redis container in tests both with JUnit5 and JUnit4. The implementation doesn’t depend on some test framework, just on the Spring Framework.

How to use multiple Redis containers in the one test case:

@RedisTestContainer  (1)
@RedisTestContainer(hostTargetProperty = "", portTargetProperty = "my.port")  (2)
class MultipleContainerInOneTest {


  1. start a Redis test container and set a host/port value of started container to default Spring Boot properties ( and spring.redis.port)

  2. start another Redis container and set a host/port value to specified properties, exactly in these properties you can read an actual value of host/port after run application context.

After test execution you can see something like this in the output:

multiple docker container result in stdout