1 min read

Trying out Embedded MongoDB

Mallim

Question

| Is it possible to run a fake embedded MongoDB for Spring Boot 2 testing?

Answer

| Yes ! It is possible and there are two choices:

Refer to

DO take note that using an embedded server cannot be considered as “full integration testing”

Option 1 - mongo-java-server

mongo-java-server is a fake implementation of MongoDB in Java that speaks the wire protocol.

Take note this one has limited features.

<dependency>
    <groupId>de.bwaldvogel</groupId>
	<artifactId>mongo-java-server</artifactId>
	<version>1.28.0</version>
	<scope>test</scope>
</dependency>

Option 2 - Flapdoodle Embedded MongoDB

Flapdoodle Embedded MongoDB provides a platform neutral way for running mongodb in unittests.

<dependency>
	<groupId>de.flapdoodle.embed</groupId>
	<artifactId>de.flapdoodle.embed.mongo</artifactId>
	<version>2.2.0</version>
	<scope>test</scope>
</dependency>

Failed Option - Fongo

fongo is a faked out in-memory mongo for Java.

It has an example of working with Spring Boot 1.

But keep getting errors when trying out with Spring Boot 2.