Skip to content

Scala library to test your redis requests with an embedded redis

License

Notifications You must be signed in to change notification settings

Sebruck/scalatest-embedded-redis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

scalatest-embedded-redis

With this project you can easily use an embedded redis in your unit tests.

It is inspired from scalatest-embedmongo.

Usage

Getting started

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.

One redis instance per test for synchronous suites

import com.github.sebruck.EmbeddedRedis
import org.scalatest.FunSuite

class MyTest extends FunSuite with EmbeddedRedis {

  test("something with redis") {
    withRedis() { port =>
      // ...
      succeed
    }
  }
}

One redis instance per test for asynchronous suites

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)
    }
  }
} 

One redis instance per suite

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)
  }
}

About

Scala library to test your redis requests with an embedded redis

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages