mongodb - Play-ReactiveMongo plugin: play2 testing a controller with a reactiveMongoApi -
in following, using play2 reactivemongo plugin in version 0.11.0.play24 (https://github.com/reactivemongo/play-reactivemongo) play 2.4.
as mentioned in documentation located @ http://reactivemongo.org/releases/0.11/documentation/tutorial/play2.html, play2 controller mongo instantiated follows:
class mycontroller @inject() (val reactivemongoapi: reactivemongoapi) extends controller mongocontroller reactivemongocomponents { } therefore, since controller class , not object, not possible use singleton in test cases.
however, not know how inject reactivemongoapi in order instantiate mycontroller() right parameters in test case (scalacheck or other...)
do have idea/example on how test such controller scalacheck or specs2?
thank in advance!
you can produce mock reactivemongoapi (depending mock framework use):
val reactivemongoapi = mock[reactivemongoapi] and can this:
new mycontroller(reactivemongoapi) that's simplest approach. use actual reactivemongoapi object:
val app = new guiceapplicationbuilder() .in(mode.test) .configure("play.modules.enabled" -> "play.modules.reactivemongo.reactivemongomodule") .build val reactivemongoapi = app.injector.instanceof[reactivemongoapi] if gets more complicated, example, partially mocked nested dependency tree (this more integration testing unit testing), may want partially mock guice framework explained here.
Comments
Post a Comment