https://github.com/jupiter-tools/spring-test-redis
Tools to write integration tests of Spring Framework with Redis
https://github.com/jupiter-tools/spring-test-redis
redis spring-boot spring-boot-redis spring-boot-test spring-data-redis spring-redis testcontainers
Last synced: 10 months ago
JSON representation
Tools to write integration tests of Spring Framework with Redis
- Host: GitHub
- URL: https://github.com/jupiter-tools/spring-test-redis
- Owner: jupiter-tools
- Created: 2019-05-23T13:54:08.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2024-08-05T21:30:34.000Z (almost 2 years ago)
- Last Synced: 2025-07-10T21:07:07.773Z (11 months ago)
- Topics: redis, spring-boot, spring-boot-redis, spring-boot-test, spring-data-redis, spring-redis, testcontainers
- Language: Java
- Homepage: http://jupiter-tools.com
- Size: 413 KB
- Stars: 2
- Watchers: 1
- Forks: 3
- Open Issues: 3
-
Metadata Files:
- Readme: README.adoc
Awesome Lists containing this project
README
:toc: preamble
# Spring Test Redis
image:https://travis-ci.com/jupiter-tools/spring-test-redis.svg?branch=master["Build Status", link="https://travis-ci.com/jupiter-tools/spring-test-redis"]
Tools to write integration tests of Spring Framework with Redis.
## Overview
image:./images/redis.png[redis container scheme,300]
## How to write integration tests on Spring Framework with Redis
Add this library in dependencies:
[source,xml]
----
com.jupiter-tools
spring-test-redis
0.1
----
And now, you can start Redis in docker (TestContainers) by the using of `@RedisTestContainer` annotation in tests:
[source, java]
----
@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:
[source, java]
----
@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:
image:./images/multiple_containers.png[multiple docker container result in stdout]