Skip to content

Simple scala lib to "unit" test your mongodb request

Notifications You must be signed in to change notification settings

aratatous/scalatest-embedmongo

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SCALATEST EMBED MONGO

This project provides API to use an embedMongo database in your Scala tests

It is directly inspired by spec2-embedmongo project.

This works in a Java 6+ environment

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, 2.13 OK (1.0.0 version)
  • manage port uses for parallel testing TODO
  • helpers for setup test with embedMongo TODO

Installation

Git repo

scalatest-embedmongo is a SBT project.
It use 1.6.2 sbt version.
Only the following Scala versions 2.11 & 2.12 & 2.13 are currently supported.
The current version of the library is 1.0.0.

Maven dependency


    <dependency>
        <groupId>com.github.simplyscala</groupId>
        <artifactId>scalatest-embedmongo_2.13</artifactId>
        <version>1.0.0</version>
        <scope>test</scope>
    </dependency>

SBT dependency


    libraryDependencies += "com.github.simplyscala" %% "scalatest-embedmongo" % "1.0.0" % "test",

with SBT


   resolvers += "SSO" at "https://nginx.org/nexus/content/repositories"

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

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") {
            ...
        }
    }

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 !

footpage

This file is written with .textile extension

Maven Repository Usage Guide
Sonatype project JIRA Page

About

Simple scala lib to "unit" test your mongodb request

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Scala 100.0%