Scala Play测试在依赖注入期间无法找到WSClient

时间:2016-08-30 11:33:52

标签: scala testing playframework dependency-injection

我尝试使用以下内容将DI课程纳入单元测试:

val injector = new GuiceInjectorBuilder().injector()
val secured = injector.instanceOf[Secured]

然而,当我尝试运行它时,我收到以下错误:

[info] Exception encountered when attempting to run a suite with class name: org.scalatest.DeferredAbortedSuite *** ABORTED ***
[info]   com.google.inject.ConfigurationException: Guice configuration errors:
[info] 
[info] 1) No implementation for play.api.libs.ws.WSClient was bound.
[info]   while locating play.api.libs.ws.WSClient
[info]     for parameter 3 at com.fredley.Secured.<init>(Secured.scala:36)
[info]   while locating com.fredley.Secured

...

我做错了什么?

1 个答案:

答案 0 :(得分:2)

问题不是从应用程序构建注入器(意味着未加载Play依赖项)。这解决了这个问题:

val application = new GuiceApplicationBuilder().build
val secured = application.injector.instanceOf[Secured]