Monday, September 30, 2013

EmbedMongo and the Play Framework


We would like to use integrations and unit tests that don't require an actual database. As of this writing there are several solutions to this problem with relational databases, however we are using Mongo, a popular NOSQL db.

We have found using embedmongo (https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo) useful for this task.

Here is a sample of how to make this work...


The above describes the quick and dirty steps for starting up the embedded Mongo instance in an integration test.

In practice, I have created an EmbeddedMongo class with a startup and teardown method which makes use of the play framework properties file to populate the appropriate port for testing and to encapsulate the private members mentioned above.

No comments:

Post a Comment