Package akka.actor.testkit.typed.javadsl
Class TestKitJunitResource
- java.lang.Object
-
- org.junit.rules.ExternalResource
-
- akka.actor.testkit.typed.javadsl.TestKitJunitResource
-
- All Implemented Interfaces:
org.junit.rules.TestRule
public final class TestKitJunitResource extends org.junit.rules.ExternalResource
A Junit external resource for theActorTestKit
, making it possible to have Junit manage the lifecycle of the testkit. The testkit will be automatically shut down when the test completes or fails.Note that Junit is not provided as a transitive dependency of the testkit module but must be added explicitly to your project to use this.
Example:
public class MyActorTest { @ClassRule public static final TestKitResource testKit = new TestKitResource(); @Test public void testBlah() throws Exception { // spawn actors etc using the testKit ActorRef<Message> ref = testKit.spawn(behavior); } }
By default config is loaded from
application-test.conf
if that exists, otherwise using default configuration from the reference.conf resources that ship with the Akka libraries. The application.conf of your project is not used in this case. A specific configuration can be passed as constructor parameter.
-
-
Constructor Summary
Constructors Constructor Description TestKitJunitResource()
Config loaded fromapplication-test.conf
if that exists, otherwise using default configuration from the reference.conf resources that ship with the Akka libraries.TestKitJunitResource(ActorTestKit _kit)
TestKitJunitResource(ActorSystem<?> system)
Use a customActorSystem
for the actor system.TestKitJunitResource(com.typesafe.config.Config customConfig)
Use a custom config for the actor system.TestKitJunitResource(com.typesafe.config.Config customConfig, TestKitSettings settings)
Use a custom config for the actor system, and a customTestKitSettings
.TestKitJunitResource(java.lang.String customConfig)
Use a custom config for the actor system.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
after()
TestProbe<DeadLetter>
createDeadLetterProbe()
See corresponding method onActorTestKit
TestProbe<Dropped>
createDroppedMessageProbe()
See corresponding method onActorTestKit
<M> TestProbe<M>
createTestProbe()
See corresponding method onActorTestKit
<M> TestProbe<M>
createTestProbe(java.lang.Class<M> clazz)
See corresponding method onActorTestKit
<M> TestProbe<M>
createTestProbe(java.lang.String name)
See corresponding method onActorTestKit
<M> TestProbe<M>
createTestProbe(java.lang.String name, java.lang.Class<M> clazz)
See corresponding method onActorTestKit
TestProbe<UnhandledMessage>
createUnhandledMessageProbe()
See corresponding method onActorTestKit
Scheduler
scheduler()
See corresponding method onActorTestKit
SerializationTestKit
serializationTestKit()
Additional testing utilities for serialization.<T> ActorRef<T>
spawn(Behavior<T> behavior)
See corresponding method onActorTestKit
<T> ActorRef<T>
spawn(Behavior<T> behavior, Props props)
See corresponding method onActorTestKit
<T> ActorRef<T>
spawn(Behavior<T> behavior, java.lang.String name)
See corresponding method onActorTestKit
<T> ActorRef<T>
spawn(Behavior<T> behavior, java.lang.String name, Props props)
See corresponding method onActorTestKit
<T> void
stop(ActorRef<T> ref)
See corresponding method onActorTestKit
<T> void
stop(ActorRef<T> ref, java.time.Duration max)
See corresponding method onActorTestKit
ActorSystem<java.lang.Void>
system()
See corresponding method onActorTestKit
ActorTestKit
testKit()
TestKitSettings
testKitSettings()
See corresponding method onActorTestKit
Timeout
timeout()
See corresponding method onActorTestKit
-
-
-
Constructor Detail
-
TestKitJunitResource
public TestKitJunitResource(ActorTestKit _kit)
-
TestKitJunitResource
public TestKitJunitResource()
Config loaded fromapplication-test.conf
if that exists, otherwise using default configuration from the reference.conf resources that ship with the Akka libraries. The application.conf of your project is not used in this case.
-
TestKitJunitResource
public TestKitJunitResource(ActorSystem<?> system)
Use a customActorSystem
for the actor system.
-
TestKitJunitResource
public TestKitJunitResource(java.lang.String customConfig)
Use a custom config for the actor system.
-
TestKitJunitResource
public TestKitJunitResource(com.typesafe.config.Config customConfig)
Use a custom config for the actor system.
-
TestKitJunitResource
public TestKitJunitResource(com.typesafe.config.Config customConfig, TestKitSettings settings)
Use a custom config for the actor system, and a customTestKitSettings
.
-
-
Method Detail
-
after
public void after()
- Overrides:
after
in classorg.junit.rules.ExternalResource
-
createDeadLetterProbe
public TestProbe<DeadLetter> createDeadLetterProbe()
See corresponding method onActorTestKit
-
createDroppedMessageProbe
public TestProbe<Dropped> createDroppedMessageProbe()
See corresponding method onActorTestKit
-
createTestProbe
public <M> TestProbe<M> createTestProbe()
See corresponding method onActorTestKit
-
createTestProbe
public <M> TestProbe<M> createTestProbe(java.lang.Class<M> clazz)
See corresponding method onActorTestKit
-
createTestProbe
public <M> TestProbe<M> createTestProbe(java.lang.String name, java.lang.Class<M> clazz)
See corresponding method onActorTestKit
-
createTestProbe
public <M> TestProbe<M> createTestProbe(java.lang.String name)
See corresponding method onActorTestKit
-
createUnhandledMessageProbe
public TestProbe<UnhandledMessage> createUnhandledMessageProbe()
See corresponding method onActorTestKit
-
scheduler
public Scheduler scheduler()
See corresponding method onActorTestKit
-
serializationTestKit
public SerializationTestKit serializationTestKit()
Additional testing utilities for serialization.
-
spawn
public <T> ActorRef<T> spawn(Behavior<T> behavior)
See corresponding method onActorTestKit
-
spawn
public <T> ActorRef<T> spawn(Behavior<T> behavior, java.lang.String name)
See corresponding method onActorTestKit
-
spawn
public <T> ActorRef<T> spawn(Behavior<T> behavior, Props props)
See corresponding method onActorTestKit
-
spawn
public <T> ActorRef<T> spawn(Behavior<T> behavior, java.lang.String name, Props props)
See corresponding method onActorTestKit
-
stop
public <T> void stop(ActorRef<T> ref, java.time.Duration max)
See corresponding method onActorTestKit
-
stop
public <T> void stop(ActorRef<T> ref)
See corresponding method onActorTestKit
-
system
public ActorSystem<java.lang.Void> system()
See corresponding method onActorTestKit
-
testKit
public ActorTestKit testKit()
-
testKitSettings
public TestKitSettings testKitSettings()
See corresponding method onActorTestKit
-
timeout
public Timeout timeout()
See corresponding method onActorTestKit
-
-