简体   繁体   中英

could not find implicit value for parameter system: akka.actor.ActorSystem

I am creating a unit test case for an Akka Actor using 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

Getting the following error in creation of 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.

I am very new to this. Kindly help.

All instances of actors, TestActorRef or actual real instances, need an ActorSystem to reside in. The methods that instantiate and start actors (again, test or otherwise) require an implicit ActorSystem to be in scope so that the underlying code creating that actor knows where to put it.

So, taking that into account, you just need to make sure that you add a line of code like this at the start of your test code:

implicit val system = ActorSystem()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM