akka - How to test actors with components injected by Guice in Play! scala 2.5 -
i'm using guice inject components inside actor explained in play! scala 2.5 documentation.
in application, inject unshortlinksfactory: unshortlinks.factory
in classes , create new actor this:
val unshortlinksactor = actorsystem.actorof(props(unshortlinksfactory(ws)))
the problem cannot inject components in test class (can i?) otherwise test not started. (please note use scalatest.)
how can create actor in tests? (it's fine if can create like val unshortlinksactor = system.actorof(props(unshortlinksfactory(ws)))
best able create testactorref
akka.testkit
in order have access underlyingactor
.
what in order test is:
i extends test class testkit(actorsystem("testsystem"))
.
then create props
this:
lazy val unshortlinkfactoryprops = props(unshortlinkfactory( dbconfigprovider = dbconfprovider)
here dbconfprovider
created mocked:
lazy val appbuilder = new guiceapplicationbuilder() lazy val injector = appbuilder.injector() lazy val dbconfprovider = injector.instanceof[databaseconfigprovider]
finally can have actorref this:
val actorref = testactorref[unshortlinksactor](unshortlinksfactoryprops)
and can access methods inside actor actorref.underlyingactor
.
Comments
Post a Comment