README.textile
March 21, 2017 ยท View on GitHub
h1. SCALATEST EMBED MONGO
This project provides API to use an "embedMongo database":https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo in your Scala tests
It is directly inspired by "spec2-embedmongo":https://github.com/athieriot/specs2-embedmongo project.
This works in a Java 6+ environment
h2. Roadmap
- trait to use embedMongo OK (0.1 version)
- trait to use embedMongo fixture OK (0.1 version)
- deploy on maven central OK (0.1 version)
- build on scala 2.10 OK (0.2 version)
- cross compilation 2.9 & 2.10 OK (0.2 version)
- manage port uses for parallel testing TODO
- helpers for setup test with embedMongo TODO
h2. Installation
h3. Git repo
scalatest-embedmongo is a SBT project. It use 0.13.13 sbt version. Only the following Scala versions 2.11 & 2.12 are currently supported. The current version of the library is 0.2.4.
h3. Maven dependency
com.github.simplyscala
scalatest-embedmongo_2.12
0.2.4
test
h3. SBT dependency
libraryDependencies += "com.github.simplyscala" %% "scalatest-embedmongo" % "0.2.4" % "test"
h3. Simple JAR file
"0.2.4 jar version":https://oss.sonatype.org/content/repositories/releases/com/github/simplyscala/scalatest-embedmongo_2.12/0.2.4/scalatest-embedmongo_2.12-0.2.4.jar
h3. Try SNAPSHOT version
You could be tempted to try SNAPSHOT version to test project's next features.
h4. with Maven
maven snapshot
https://oss.sonatype.org/content/repositories/snapshots
...
com.github.simplyscala
scalatest-embedmongo_2.12
0.2.5-SNAPSHOT
test
h4. with SBT
resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"
libraryDependencies += "com.github.simplyscala" %% "scalatest-embedmongo" % "0.2.5-SNAPSHOT"
h2. Usage
In order to use scalatest-embedmongo API, your test must extends MongoEmbedDatabase as follows:
import com.github.simplyscala.MongoEmbedDatabase
...
MyTest extends FunSuite with MongoEmbedDatabase
h3. Basic Usage (mutable way)
MyTest extends FunSuite with MongoEmbedDatabase with BeforeAndAfter {
var mongoProps: MongodProps = null
before {
mongoProps = mongoStart() // by default port = 12345 & version = Version.3.3.1
} // add your own port & version parameters in mongoStart method if you need it
after { mongoStop(mongoProps) }
test("some test with mongo") {
...
}
}
h3. Immutable way usage
You can use fixture to start/stop the embed server with immutable way :
MyTest extends FunSuite with MongoEmbedDatabase {
test("test with fixture") {
//add your own port & version parameters in withEmbedMongoFixture method if you need it
withEmbedMongoFixture() { mongodProps =>
// do some mongo database operations
// in this fixture the dabatase is started
// at the end of this fixture the database is stopped
}
}
}
Be careful if you launch yours tests in parallel you could have some trouble because of mongodb port multiples uses !
h5. footpage
This file is written with .textile extension
- http://en.wikipedia.org/wiki/Textile_%28markup_language%29
- http://textile.sitemonks.com
- http://redcloth.org/hobix.com/textile/
"Maven Repository Usage Guide":https://docs.sonatype.org/display/Repository/Sonatype+OSS+Maven+Repository+Usage+Guide "Sonatype project JIRA Page":https://issues.sonatype.org/browse/OSSRH-5163