我们正在使用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 }
任何指针?