<dependency> <groupId>com.typesafe.akka</groupId> <artifactId>akka-testkit_2.12</artifactId> <version>2.6.15</version> <scope>test</scope> </dependency> import akka.actor.AbstractActor; public class MyActor extends AbstractActor { // ... @Override public AbstractActor.Receive createReceive() { return receiveBuilder() .build(); } } import static org.junit.Assert.assertEquals; import org.junit.Test; import akka.actor.ActorRef; import akka.actor.ActorSystem; import akka.testkit.javadsl.TestKit; public class MyActorTest { ActorSystem system = ActorSystem.create(); ActorRef myActor = system.actorOf(Props.create(MyActor.class)); @Test public void testMyActor() { final TestKit testProbe = new TestKit(system); myActor.tell("Hello", testProbe.getRef()); testProbe.expectMsgEquals("Expected response"); assertEquals("Expected response", testProbe.getLastMessage().toString()); } @After public void tearDown() { TestKit.shutdownActorSystem(system); } }


上一篇:
下一篇:
切换中文