delki8
delki8

Reputation: 429

"router not found" on unit testing PlayFramework Controllers

I'm having some trouble trying to unit test my controllers following the play framework documentation steps.

I've created a new app using the java template. Replaced the generated ApplicationTest with the ApplicationTest of the docs, corrected the compile errors related to wrong packages but there still something wrong with the additionalConfigurations that are passed to the FakeApplication (ImmutableMap.of("play.http.router", "javaguide.tests.Routes")) I've tried a lot of different names and directories at javaguide.tests.Routes, but i get always the error below.

[error] 
[error] 1) Error in custom provider, Configuration error: Configuration error[Router not found: javaguide.tests.Routes]
[error]   while locating play.api.test.FakeRouterProvider
[error]   while locating play.api.routing.Router
[error] 
[error] 1 error, took 2.931 sec
[error]     at com.google.inject.internal.InjectorImpl$2.get(InjectorImpl.java:1025)
[error]     at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1051)
[error]     at play.api.inject.guice.GuiceInjector.instanceOf(GuiceInjectorBuilder.scala:321)
[error]     at play.api.inject.guice.GuiceInjector.instanceOf(GuiceInjectorBuilder.scala:316)
[error]     at play.api.Application$class.routes(Application.scala:111)
[error]     at play.api.test.FakeApplication.routes(Fakes.scala:197)
[error]     at play.api.Play$.start(Play.scala:89)
[error]     at play.api.Play.start(Play.scala)
[error]     at play.test.Helpers.start(Helpers.java:450)
[error]     at play.test.WithApplication.startPlay(WithApplication.java:44)
[error]     ...
[error] Caused by: Configuration error: Configuration error[Router not found: javaguide.tests.Routes]
[error]     at play.api.Configuration$.configError(Configuration.scala:178)
[error]     at play.api.Configuration.reportError(Configuration.scala:829)
[error]     at play.api.routing.Router$$anonfun$load$2.apply(Router.scala:67)
[error]     at play.api.routing.Router$$anonfun$load$2.apply(Router.scala:66)
[error]     at scala.Option.map(Option.scala:146)
[error]     at play.api.routing.Router$.load(Router.scala:66)
[error]     at play.api.inject.RoutesProvider.get$lzycompute(BuiltinModule.scala:66)
[error]     at play.api.inject.RoutesProvider.get(BuiltinModule.scala:63)
[error]     at play.api.test.FakeRouterProvider.get$lzycompute(Fakes.scala:259)
[error]     at play.api.test.FakeRouterProvider.get(Fakes.scala:259)
[error]     at play.api.test.FakeRouterProvider.get(Fakes.scala:258)
[error]     at com.google.inject.internal.ProviderInternalFactory.provision(ProviderInternalFactory.java:81)
[error]     at com.google.inject.internal.BoundProviderFactory.provision(BoundProviderFactory.java:72)
[error]     at com.google.inject.internal.ProviderInternalFactory.circularGet(ProviderInternalFactory.java:61)
[error]     at com.google.inject.internal.BoundProviderFactory.get(BoundProviderFactory.java:62)
[error]     at com.google.inject.internal.InjectorImpl$2$1.call(InjectorImpl.java:1016)
[error]     at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1092)
[error]     at com.google.inject.internal.InjectorImpl$2.get(InjectorImpl.java:1012)
[error]     ... 44 more
[error] Failed: Total 21, Failed 1, Errors 0, Passed 19, Skipped 1

Did anyone knows what I'm missing or can share a reference to a github project that have this kind of tests working?

If it helps, the anatomy of a Play Framework app: https://playframework.com/documentation/2.4.x/Anatomy

Upvotes: 0

Views: 1992

Answers (2)

bravo2
bravo2

Reputation: 693

I was facing the same issue yesterday, and I have just answered my own question, please see if the answer to this question would help: Play 2.4: How do I disable routes file loading during unit tests?

Upvotes: 1

jacks
jacks

Reputation: 4783

Can you check that you have specified your routes file in the package where it needs to be ie. javaguide.tests

javaguide.tests.routes:

GET  /          controllers.Application.index()

Upvotes: 0

Related Questions