scala - Functional Tests in Play 2.4.6 when using compile time DI -
i'm using play 2.4.6 compile time dependency injection , scalatest. controller's constructor has few parameters, , in applicationloader create it. here code:
class bootstraploader extends applicationloader { def load(context: context) = { new appcomponents(context).application } } class appcomponents(context: context) extends builtincomponentsfromcontext(context) ningwscomponents { lazy val router = new routes(httperrorhandler, authenticationcontroller, applicationcontroller, assets) lazy val applicationcontroller = new controllers.application() lazy val authenticationcontroller = new controllers.authentication()(configuration, wsapi.client) lazy val assets = new controllers.assets(httperrorhandler) } class authentication(implicit configuration: configuration, val ws: wsclient) extends controller { def login = action { implicit request => unauthorized(s"${redirecturl}") } } class authenticationspec extends playspec oneapppersuite { implicit val configuration: configuration = app.configuration implicit val wsclient: wsclient = ws.client(app) "when user not logged-in" should { "return status code unauthorized(401) redirect url" in { 1 mustequal 2 } } } when i'm running test i'm getting following error:
[info] exception encountered when attempting run suite class name: controllers.authenticationspec *** aborted *** [info] com.google.inject.provisionexception: unable provision, see following errors: [info] [info] 1) not find suitable constructor in controllers.authentication. classes must have either 1 (and one) constructor annotated @inject or zero-argument constructor not private. [info] @ controllers.authentication.class(authentication.scala:19) [info] while locating controllers.authentication [info] parameter 1 @ router.routes.<init>(routes.scala:35) [info] while locating router.routes [info] while locating play.api.test.fakerouterprovider [info] while locating play.api.routing.router [info] [info] 1 error [info] @ com.google.inject.internal.injectorimpl$2.get(injectorimpl.java:1025) [info] @ com.google.inject.internal.injectorimpl.getinstance(injectorimpl.java:1051) [info] @ play.api.inject.guice.guiceinjector.instanceof(guiceinjectorbuilder.scala:321) [info] @ play.api.inject.guice.guiceinjector.instanceof(guiceinjectorbuilder.scala:316) [info] @ play.api.application$class.routes(application.scala:112) [info] @ play.api.test.fakeapplication.routes(fakes.scala:197) [info] @ play.api.play$$anonfun$start$1.apply$mcv$sp(play.scala:90) [info] @ play.api.play$$anonfun$start$1.apply(play.scala:87) [info] @ play.api.play$$anonfun$start$1.apply(play.scala:87) [info] @ play.utils.threads$.withcontextclassloader(threads.scala:21) fakeapplication use guiceapplicationbuilder, of course not work.
what should run such tests?
thanks
override implicit lazy val app = new bootstraploader().load( applicationloader.createcontext( new environment( new file("."), applicationloader.getclass.getclassloader, mode.test))) it works in play 2.5.1
Comments
Post a Comment