Library to allow mocking of a Play-ReactiveMongo app's MongoDB back end.
The intention of this library is to facilitate the writing of tests which:
- Cover DAO- or Service-level logic around backend database calls
- Allow a level of component testing beyond simple unit tests
- Execute far faster than conventional "seeded database" tests
- Eliminate the potential issues around inconsistent and/or shared database state
This library is currently a work-in-progress and should not be considered useful until an artifact has been publicly published.
Due to the nature of mocking method calls, it is essential that the version of this library matches exactly the version of [https://github.com/ReactiveMongo/Play-ReactiveMongo].
Two modes of usage exist - the first will be more familiar to those who have used mocking libraries such as Mockito before. The second is a "higher-level" abstraction over the Mongo datastore, where the entire store (or at least, the part(s) being tested) are represented as a Map of Maps. If you are executing complex multi-Collection join-like queries, it may end up being a more readable solution.
Mix in MappedMongoMocking
and define mockData
- a Map[String, Set[JsObject]
i.e. mapping CollectionName to its contents. That's it! All of your Mongo find()
operations will now work against this data.
Standing on the shoulders of giants: