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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With