Skip to content
Tools to write integration tests of Spring Framework with Redis
Branch: master
Clone or download
Latest commit 4810207 Jul 12, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
images change the System.out.println on logger May 25, 2019
src Merge pull request #4 from jupiter-tools/feature/add-a-readme May 25, 2019
.gitignore draft version of multiple redis containers May 24, 2019
.travis.yml openjdk Jul 12, 2019
README.adoc improve the documentation May 25, 2019


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

You can’t perform that action at this time.