Perhaps at least with versions 1.3 and 2.0 and the akka-testkit library.
You do something like this to set up your actor:
@Before public void initActor() { actorSystem = ActorSystem.apply(); actorRef = TestActorRef.apply(new AbstractFunction0() { @Override public Pi.Worker apply() { return new Pi.Worker(); } }, actorSystem); }
Then you can use the TestProbe class to test your actor (for version 1.3 it is slightly different):
@Test public void calculatePiFor0() { TestProbe testProbe = TestProbe.apply(actorSystem); Pi.Work work = new Pi.Work(0, 0); actorRef.tell(work, testProbe.ref()); testProbe.expectMsgClass(Pi.Result.class); TestActor.Message message = testProbe.lastMessage(); Pi.Result resultMsg = (Pi.Result) message.msg(); assertEquals(0.0, resultMsg.getValue(), 0.0000000001); }
The blog that I wrote about some of my impressions is more available: http://fhopf.blogspot.com/2012/03/testing-akka-actors-from-java.html
fhopf source share