无法获得Guice Injector Instance玩2.5 scalatest

时间:2016-11-16 22:30:01

标签: scala playframework guice scalatest playframework-2.5

我们正在使用scalatestplus-play 1.5.1版本。

以下是BaseTestClass的代码段:

trait GuiceMock extends Suite with OneAppPerTest with BeforeAndAfterAll {

    def injector(): Injector = { app.injector }

    override def newAppForTest(testData: TestData): Application = {
        new GuiceApplicationBuilder().configure().configure(configurationMap)
          .disable(classOf[SomeModule], classOf[RedisSentinelModule])
          .bindings(getTestModule())
          .in(Mode.Test).build()
    }
    ...
}

在我的测试中,我需要一个类似于下面的注射器实例:

trait ControllerFixture extends MockitoSugar with GuiceMock { 
  ...

  val someClient = injector.instanceOf(classOf[SomeClient])

  ...
}

但我遇到了一个空指针异常@ this line:

 def injector(): Injector = { app.injector }

任何指针?

0 个答案:

没有答案