<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-testkit_2.12</artifactId>
<version>2.6.10</version>
<scope>test</scope>
</dependency>
groovy
dependencies {
testCompile "com.typesafe.akka:akka-testkit_2.12:2.6.10"
}
public class MyActorTest extends TestKit {
public MyActorTest() {
ActorSystem system = ActorSystem.create();
TestProbe probe = new TestProbe(system);
ActorRef actor = system.actorOf(Props.create(MyActor.class));
actor.tell("Hello", probe.ref());
probe.expectMsg("Hello");
}
}
public class MyActorTest extends TestKit {
public MyActorTest() {
ActorSystem system = ActorSystem.create();
TestProbe probe = new TestProbe(system);
ActorRef actor = system.actorOf(Props.create(MyActor.class, probe.ref()));
actor.tell("Hello", getTestActor());
probe.expectMsg("Hello");
// ...
}
}
public class MyActorTest extends TestKit {
public MyActorTest() {
ActorSystem system = ActorSystem.create();
TestProbe probe = new TestProbe(system);
ActorRef actor = system.actorOf(Props.create(MyActor.class, probe.ref()));
actor.tell("Hello", getTestActor());
probe.expectMsg("Hello");
probe.reply("World");
expectMsg("World");
}
}
public class MyActorTest extends TestKit {
public MyActorTest() {
ActorSystem system = ActorSystem.create();
TestProbe probe = new TestProbe(system);
ActorRef actor = system.actorOf(Props.create(MyActor.class));
probe.setParent(getTestActor());
probe.setIgnoreMsg(ignore -> true);
actor.tell("Hello", probe.ref());
probe.expectNoMessage();
}
}
public class MyActorTest extends TestKit {
public MyActorTest() {
ActorSystem system = ActorSystem.create();
TestProbe probe = new TestProbe(system);
ActorRef actor = system.actorOf(Props.create(MyActor.class));
new JavaTestKit(system) {
{
new Within(duration("10 seconds")) {
protected void run() {
for (int i = 1; i <= 10000; i++) {
actor.tell(i, getRef());
}
}
};
for (int i = 1; i <= 10000; i++) {
expectMsg(i);
}
probe.reply("Done");
expectMsg("Done");
}
};
}
}
public class MyActorSystemTest extends TestKit {
public MyActorSystemTest() {
ActorSystem system = ActorSystem.create();
ActorRef actor1 = system.actorOf(Props.create(MyActor1.class));
ActorRef actor2 = system.actorOf(Props.create(MyActor2.class));
TestProbe probe = new TestProbe(system);
actor1.tell("Hello", probe.ref());
probe.expectMsg("World");
probe.reply("Done");
expectMsg("Done");
}
}
public class MyActorTest extends TestKit {
public MyActorTest() {
ActorSystem system = ActorSystem.create();
TestProbe probe = new TestProbe(system);
ActorRef actor = system.actorOf(Props.create(MyActor.class, probe.ref()));
actor.tell("Hello", getTestActor());
probe.expectMsg("Hello");
probe.reply("World");
expectMsg("World");
}
}
public class MyActorTest extends TestKit {
public MyActorTest() {
ActorSystem system = ActorSystem.create();
TestProbe probe = new TestProbe(system);
TestFSMRef<MyState, MyData, MyActor> actor = TestFSMRef.apply(new MyActor(probe.ref()));
actor.tell(new MyMessage(), getTestActor());
assert(actor.stateName() == MyState.READY);
probe.expectMsg("Hello");
}
}
public class MyActorTest extends TestKit {
public MyActorTest() {
ActorSystem system = ActorSystem.create();
TestProbe probe = new TestProbe(system);
TestProbe delayProbe = new TestProbe(system);
delayProbe.setDelay(1000);
actor.tell("Hello", getTestActor());
probe.expectMsgEquals(delayProbe, "Hello");
probe.reply("World");
expectMsgEquals("World");
}
}