Configure & use mongodb mockup server for unit testing Configure & use mongodb mockup server for unit testing mongodb mongodb

Configure & use mongodb mockup server for unit testing


fongo might be what you are looking for.


I wrote a MongoDB fake implementation in Java: mongo-java-server (see this answer).


We're actually working on such a test system and it's quite feasible. In our approach our test framework extends the standard test case class (JUnit in our case but TestNG seems more capable) that sets up and tears down the various database dependecies with each test using the following steps :

Test Suite Setup

1) Start mongod process (we use ProcessBuilder, store Process instance)

Test Setup :

2) Run mongo with a test specific .js file to produce initial data state

Test

3) Run test

Test Teardown

4) Drop database

Test Suite Teardown

5) Stop mongod process (process.destroy())

Since starting and stopping mongod is the only time consuming thing i'd strongly suggest doing this as little as possible. Preferably once for the entire test suite. Our stuff isn't finished yet but early results are positive. I don't think many alternatives are available. No mongo mock library is available at time of writing and mongod does not have a in-memory/embedded mode.