So, my understanding of the Akka-Actor system is that you have to do this through properties, and then right?
Thus, create an actor through the props, and when testing, simply return the spy to the actor.
so this should give you the result:
val testActorRef = TestActorRef(spy(new TestActor)) val testActorSpy = testActorRef.underlyingActor
Keep in mind that the primary agent is destroyed when the actor restarts. therefore, mockery of this may not be the best option.
If you use the actor directly through the system, you can also test and bypass the stream base system.
See this (paste the code below for java).
static class MyActor extends UntypedActor { public void onReceive(Object o) throws Exception { if (o.equals("say42")) { getSender().tell(42, getSelf()); } else if (o instanceof Exception) { throw (Exception) o; } } public boolean testMe() { return true; } } @Test public void demonstrateTestActorRef() { final Props props = Props.create(MyActor.class); final TestActorRef<MyActor> ref = TestActorRef.create(system, props, "testA"); final MyActor actor = ref.underlyingActor(); assertTrue(actor.testMe()); }
source share