Testing Akka actors that mixin Stash with TestActorRef

I was able to test actors with Stash like this:

val actor = TestActorRef(Props(new MyActorWithStash()).withDispatcher("deque"))

TestActorRef can't be used together with Stash. TestActorRef requires a CallingThreadMailbox and Stash requires DequeBasedMessageQueueSemantics. The documentation should include this limitation and the error messages should be improved.


Using the default akka dispatcher allowed me to use Stash and TestActorRef:

val myActor = TestActorRef[MyActor](Props(classOf[MyActor]).withDispatcher("akka.actor.default-dispatcher"))

Note that this means your tests will no longer use the default CallingThreadDispatcher and will lose the benefits highlighted in the akka docs

Tags:

Scala

Akka