Skip to content
Advertisement

Embedded MongoDB when running integration tests

My question is a variation of this one.

Since my Java Web-app project requires a lot of read filters/queries and interfaces with tools like GridFS, I’m struggling to think of a sensible way to employ MongoDB in the way the above solution suggests.

Therefore, I’m considering running an embedded instance of MongoDB alongside my integration tests. I’d like it to start up automatically (either for each test or the whole suite), flush the database for every test, and shut down at the end. These tests might be run on development machines as well as the CI server, so my solution will also need to be portable.

Can anyone with more knowledge on MongoDB help me get idea of the feasibility of this approach, and/or perhaps suggest any reading material that might help me get started?

I’m also open to other suggestions people might have on how I could approach this problem…

Advertisement

Answer

Here’s an updated (for 2022) version of the accepted answer from @rozky (a lot has been changed in both the Mongo and Embedded MongoDB libraries).

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement