1. Introduction

This plugin is designed to execute your integration tests with an embedded instance of a mongo database, similar to H2. Also similar to H2, it will ensure all data is cleared from the database before each test case. The Flapdoodle Embed Mongo library is used to execute the embedded database.

2. Installation

To start using this plugin, there are two options

  1. Add the plugin to your build.gradle with the provided or compileOnly scope

     provided "org.grails.plugins:embedded-mongodb:2.0.0.M1"
  2. Add the plugin to your build.gradle with the testCompile scope

     testCompile "org.grails.plugins:embedded-mongodb:2.0.0.M1"

If you choose this option, there is 1 additional step required. You must exclude the EmbeddedMongoAutoConfiguration from your Application.groovy.

Example:

 import grails.boot.GrailsApp
 import grails.boot.config.GrailsAutoConfiguration
 import org.springframework.boot.autoconfigure.EnableAutoConfiguration
 import org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration

 @EnableAutoConfiguration(exclude = [EmbeddedMongoAutoConfiguration])
 class Application extends GrailsAutoConfiguration {
     static void main(String[] args) {
         GrailsApp.run(Application, args)
     }
 }

3. Configuration

You can set the version of the database you would like to embed. If not specified, the version defined by de.flapdoodle.embed.mongo.distribution.Version.Main.PRODUCTION will be used.

 environments:
     test:
         grails:
             mongodb:
                 version: "3.2.1"

3.1. Considerations

To prevent any possible confusion with an existing running instance of a real mongo database, it is recommended to change the port for the test environment. The embedded mongo database will run on the port specified in your configuration.

 environments:
     test:
         grails:
             mongodb:
                 port: 27018