给定特征(简化)
trait A {
val eventStream: EventStream
val credentialsStorage = // something here
val userStorage = // something here
val crypto = // something here
...
lazy val authSvc = new CoreAuthentication(credentialsStorage, new AuthenticationProviderResolver, userStorage, eventStream, crypto)
}
class T extends A with TraitProvidingEventStream with FlatSpec with [lot of another traits here] {
val eventStream = systemFromTraitProvidingEventStream.eventStream
"This" should "work" in {
println(authSvc) // this is "magic"
val user = authSvc.doSomethingWithUser(...);
}
}
如果我删除标记为//this is "magic"的行,那么我将在下一行得到 NullPointerException,因此 authSvc 为空。
那里可能有什么问题?
我无法为此创建干净的小测试用例,通常效果很好