Running tests with an in-memory database

One of the reasons I chose MongoDB is that it can be easily embedded with a Spring Boot application for testing purposes. To enable an embedded MongoDB for your project, include the following dependency in Maven pom.xml:

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

Spring Boot provides auto-configuration for an embedded MongoDB, so we don't need to do anything else other than setting the local address and port in application.yml. Because, by default, we use Mongo running on Docker container, we should declare such a configuration in an additional Spring profile. This specific profile is activated during test ...

Get Mastering Spring Cloud now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.