I have an existing unit test that uses BehaviorTestKit to test the actor's behavior when it receives a Terminated signal. I am able to send a Terminated signal to it like this:
val myParentTestKit = BehaviorTestKit(ParentActor())
myParentTestKit.signal(Terminated(myChildTestKit.ref))
This works great, and I am able to observe/assert the effects of the Terminated handling of the actor.
Now, some implementation details have changed (inter-actor messaging) that makes it no longer possible to use BehaviorTestKit. I am trying to port this test to use ActorTestKit instead. I am able to spawn the parent actor like this:
val myParent = myActorTestKit.spawn(ParentActor())
However I can't figure out how to send the Terminated signal to it.
What is the correct way to send a Terminated signal when using ActorTestKit instead of BehaviorTestKit?
The actor testkit actually runs the actor "for real", so the way to trigger
Terminated
is to stop the actor. That can be done either through an explicit stop message in the protocol of the actor for which the actor returnsBehaviors.stopped
or when started through the testkit usingmyActorTestKit.stop(actorRef)
.