A JUnit5 extension to set up embedded Redis for tests.
- Junit 5
- Embedded Redis - https://github.com/signalapp/embedded-redis
- FreePortFinder - https://github.com/alexpanov/freeportfinder
Add to build.gradle.kts
testImplementation("se.svt.oss:junit5-redis-extension:3.Y.Z")
A standard junit5 extension that will start an embedded Redis server on a random port before all tests in a class
is run and shut it down after all tests are run.
System property embedded-redis.port
will be set to hold the port used by the Redis server.
Example on usage in test
@ExtendWith(EmbeddedRedisExtension::class)
class SomeIntegrationTest {
@Test
fun doSomeTest() {
val redisUri = URI.create("redis://localhost:" + System.getProperty("embedded-redis.port"))
// Do something against the redis instance
}
}
If running multiple tests within the same JVM, a new Redis instance using a new random port will be created for each
test instance.
To enforce use of the same port for each test instance, the extension can be registered programmatically with the reusePort
constructor parameter set to true.
./gradlew clean test
By default, the package uses Redis 6.0.5, as provided by the embedded-redis package.
If you wish to use another Redis version, you can do so by setting the environment variable REDIS_SERVER
to the path to your Redis-server executable, which the package will then use instead, by providing the path to the RedisServer
constructor.
t
If you have questions, concerns, bug reports, etc, please file an issue in this repository's Issue Tracker.
General instructions for contributing CONTRIBUTING.
This software is released under the:
Copyright 2018 Sveriges Television AB
Properties and various configuration files are released under CC0 1.0 Universal (Public Domain).
Gustav Grusell https://github.com/grusell