With this project you can easily use an embedded redis in your unit tests.
It is inspired from scalatest-embedmongo.
Add the following to your build.sbt
file.
libraryDependencies += "com.github.sebruck" %% "scalatest-embedded-redis" % "0.4.0"
For a working example have a look at the tests.
import com.github.sebruck.EmbeddedRedis
import org.scalatest.FunSuite
class MyTest extends FunSuite with EmbeddedRedis {
test("something with redis") {
withRedis() { port =>
// ...
succeed
}
}
}
import com.github.sebruck.EmbeddedRedis
import org.scalatest.AsyncFunSuite
import scala.concurrent.Future
class MyTest extends AsyncFunSuite with EmbeddedRedis {
test("something with redis") {
withRedisAsync() { port =>
// ...
Future.successful(succeed)
}
}
}
import com.github.sebruck.EmbeddedRedis
import org.scalatest.{BeforeAndAfterAll, FunSuite}
import redis.embedded.RedisServer
class MyTest extends FunSuite with EmbeddedRedis with BeforeAndAfterAll {
var redis: RedisServer = null
var redisPort: Int = null
override def beforeAll() = {
redis = startRedis() // A random free port is chosen
redisPort = redis.ports().get(0)
}
test("something with redis") {
// ...
}
override def afterAll() = {
stopRedis(redis)
}
}