Unit testing applications using reactivemongo

667 views
Skip to first unread message

Z. S.

unread,
Mar 22, 2017, 10:22:29 AM3/22/17
to ReactiveMongo - http://reactivemongo.org
Hi,

We were building a repository using reactivemongo and we thought of writing some unit tests. But it became apparent it would not be trivial to do. Take for example http://reactivemongo.org/releases/0.12/documentation/tutorial/getstarted.html and imagine you wanted to unit test def findPersonByAge(age: Int): Future[List[Person]] .. 

How would you go about dealing with this? Would you maybe not suggest writing a unit test at all for such methods, or would you try to mock the collection or you would build your own in memory collection implementing all the api methods such as flatMap, find, filter.

Any thoughts and ideas appreciated,

Thanks

Cédric Chantepie

unread,
Mar 22, 2017, 3:53:45 PM3/22/17
to ReactiveMongo - http://reactivemongo.org
Either integration test (requiring test DB/connection and appropriate setup), or unit tests are possible.

Ugo Bourdon

unread,
Mar 31, 2017, 4:32:57 AM3/31/17
to ReactiveMongo - http://reactivemongo.org
Hi, you can use this lovely lib ^^ to "unit test" your mongodb repository : https://github.com/SimplyScala/scalatest-embedmongo
It start for you a mongodb "in-memory" for play your request in a Unit Test.

Cédric Chantepie

unread,
Mar 31, 2017, 12:08:38 PM3/31/17
to ReactiveMongo - http://reactivemongo.org
If it starts an embedded, that's rather an integration test, as it doesn't provide test isolation.

Jordan Messec

unread,
Sep 22, 2017, 1:30:25 PM9/22/17
to ReactiveMongo - http://reactivemongo.org
That's a bold claim when the community has come to the conclusion that unit tests are not possible. Could you please provide an example of mocking out collection.find.sort.cursor.collect?

Cédric Chantepie

unread,
Sep 22, 2017, 2:17:07 PM9/22/17
to ReactiveMongo - http://reactivemongo.org
Reply all
Reply to author
Forward
0 new messages