spring-test-redis

Tools suite to write integration tests for Spring Applications with the Redis.

License

License

Categories

Categories

Redis Data Databases
GroupId

GroupId

com.jupiter-tools
ArtifactId

ArtifactId

spring-test-redis
Last Version

Last Version

0.1
Release Date

Release Date

Type

Type

jar
Description

Description

spring-test-redis
Tools suite to write integration tests for Spring Applications with the Redis.
Project URL

Project URL

https://github.com/jupiter-tools/spring-test-redis
Source Code Management

Source Code Management

https://github.com/jupiter-tools/spring-test-redis

Download spring-test-redis

How to add to project

<!-- https://jarcasting.com/artifacts/com.jupiter-tools/spring-test-redis/ -->
<dependency>
    <groupId>com.jupiter-tools</groupId>
    <artifactId>spring-test-redis</artifactId>
    <version>0.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.jupiter-tools/spring-test-redis/
implementation 'com.jupiter-tools:spring-test-redis:0.1'
// https://jarcasting.com/artifacts/com.jupiter-tools/spring-test-redis/
implementation ("com.jupiter-tools:spring-test-redis:0.1")
'com.jupiter-tools:spring-test-redis:jar:0.1'
<dependency org="com.jupiter-tools" name="spring-test-redis" rev="0.1">
  <artifact name="spring-test-redis" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.jupiter-tools', module='spring-test-redis', version='0.1')
)
libraryDependencies += "com.jupiter-tools" % "spring-test-redis" % "0.1"
[com.jupiter-tools/spring-test-redis "0.1"]

Dependencies

compile (1)

Group / Artifact Type Version
org.testcontainers : testcontainers jar 1.10.2

provided (2)

Group / Artifact Type Version
org.springframework.boot : spring-boot-starter-data-redis jar
org.springframework.boot : spring-boot-starter-test jar

test (5)

Group / Artifact Type Version
org.junit.jupiter : junit-jupiter-api jar 5.4.2
org.junit.jupiter : junit-jupiter-engine jar 5.4.2
org.junit.platform : junit-platform-engine jar 1.4.2
org.junit.platform : junit-platform-launcher jar 1.4.2
org.redisson : redisson jar 3.10.7

Project Modules

There are no modules declared in this project.

Spring Test Redis

Build Status

Tools to write integration tests of Spring Framework with Redis.

Overview

redis container scheme

How to write integration tests on Spring Framework with Redis

Add this library in dependencies:

<dependency>
    <groupId>com.jupiter-tools</groupId>
    <artifactId>spring-test-redis</artifactId>
    <version>0.1</version>
</dependency>

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

@SpringBootTest
@RedisTestContainer
class RedisTestContainerTest {

    @Autowired
    private RedisTemplate redisTemplate;

    @Test
    void readWriteValueByRedisTemplate() {
        String key = "test";
        String value = "sabracadabra";
        // Act
        redisTemplate.opsForValue().set(key, value);
        // Assert
        assertThat(redisTemplate.opsForValue().get(key)).isEqualTo(value);
    }
}

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:

@SpringBootTest
@RedisTestContainer  (1)
@RedisTestContainer(hostTargetProperty = "my.host", 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 (spring.redis.host 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

com.jupiter-tools

Versions

Version
0.1