我正在为Akka Actor创建一个单元测试用例TestActorRef.
def actorRefFactory = context
implicit def executionContext = actorRefFactory.dispatcher
implicit val OutputActor = actorRefFactory.actorOf(Props[OutputActor], "OutputActor")
val actorRef = TestActorRef[OutputActor]
val actor = actorRef.underlyingActor
Run Code Online (Sandbox Code Playgroud)
在创建actorRef时出现以下错误:
- could not find implicit value for parameter system: akka.actor.ActorSystem
- not enough arguments for method apply: (implicit t:
scala.reflect.ClassTag[org.musigma.muhpc.OutputActor], implicit system:
akka.actor.ActorSystem)akka.testkit.TestActorRef[org.musigma.muhpc.OutputActor] in object
TestActorRef. Unspecified value parameter system.
Run Code Online (Sandbox Code Playgroud)
我对此很新.请帮助.
cmb*_*ter 16
演员TestActorRef或实际真实实例的所有实例都需要ActorSystem驻留.实例化和启动actor(再次,测试或其他)的方法需要implicit ActorSystem在范围内,以便创建该actor的底层代码知道放置它的位置.
因此,考虑到这一点,您只需要确保在测试代码的开头添加一行代码:
implicit val system = ActorSystem()
Run Code Online (Sandbox Code Playgroud)