Class ActorTestKit
Provides a typed actor system started on creation, used for all test cases and shut down when shutdown is called.
The actor system has a custom guardian that allows for spawning arbitrary actors using the spawn methods.
Designed to work with any test framework, but framework glue code that calls shutdown after all tests has run needs to be provided by the user.
For synchronous testing of a Behavior see BehaviorTestKit
-
Method Summary
Modifier and TypeMethodDescriptionstatic com.typesafe.config.ConfigConfig loaded fromapplication-test.conf, which is used if no specific config is given.static ActorTestKitapply()Create a testkit named from the ActorTestKit class.static ActorTestKitapply(com.typesafe.config.Config customConfig) Create a testkit named from the ActorTestKit class, and use a custom config for the actor system.static ActorTestKitCreate a testkit using the provided name.static ActorTestKitCreate a test kit named based on the provided name, and uses the provided custom config for the actor system.static ActorTestKitapply(String name, com.typesafe.config.Config customConfig, TestKitSettings settings) Create anpekko.actor.typed.ActorSystemnamed based on the provided name, use the provided custom config for the actor system, and the testkit will use the provided setting.static ActorTestKitapply(ActorSystem<?> system) Create a testkit from the provided actor system.com.typesafe.config.Configconfig()<M> TestProbe<M>Shortcut for creating a new test probe for the testkit actor system<M> TestProbe<M>createTestProbe(String name) Shortcut for creating a new named test probe for the testkit actor systemActorSystem<?>name()Additional testing utilities for serialization.static voidshutdown(ActorSystem<?> system) Shutdown the givenpekko.actor.typed.ActorSystemand block until it shuts down, if more time thanTestKitSettings.DefaultActorSystemShutdownTimeoutpasses an exception is thrownstatic voidshutdown(ActorSystem<?> system, scala.concurrent.duration.Duration timeout, boolean throwIfShutdownFails) Shutdown the givenpekko.actor.typed.ActorSystemand block until it shuts down or thedurationhits.static booleanvoid<T> ActorRef<T>Spawn the given behavior.<T> ActorRef<T>Spawn the given behavior.<T> ActorRef<T>Spawn the given behavior.<T> ActorRef<T>Spawn the given behavior.<T> voidStop the actor under test and wait until it terminates.<T> scala.concurrent.duration.FiniteDurationActorSystem<scala.runtime.Nothing$>system()INTERNAL APItimeout()
-
Method Details
-
apply
Create a testkit named from the ActorTestKit class.When the test has completed you should terminate the
ActorSystemand the testkit withshutdownTestKit().Config loaded from
application-test.confif 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. -
apply
Create a testkit from the provided actor system.When the test has completed you should terminate the
ActorSystemand the testkit withshutdownTestKit().Config loaded from the provided actor if that exists, otherwise using default configuration from the reference.conf resources that ship with the Akka libraries.
-
apply
Create a testkit using the provided name.It will create an
pekko.actor.typed.ActorSystemwith this name, e.g. threads will include the name. When the test has completed you should terminate theActorSystemand the testkit withshutdownTestKit().Config loaded from
application-test.confif 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. -
apply
Create a testkit named from the ActorTestKit class, and use a custom config for the actor system.It will also used the provided customConfig provided to create the
ActorSystemWhen the test has completed you should terminate the
ActorSystemand the testkit withshutdownTestKit(). -
apply
Create a test kit named based on the provided name, and uses the provided custom config for the actor system.It will create an
pekko.actor.typed.ActorSystemwith this name, e.g. threads will include the name.It will also used the provided customConfig provided to create the
ActorSystemWhen the test has completed you should terminate the
ActorSystemand the testkit withshutdownTestKit(). -
apply
public static ActorTestKit apply(String name, com.typesafe.config.Config customConfig, TestKitSettings settings) Create anpekko.actor.typed.ActorSystemnamed based on the provided name, use the provided custom config for the actor system, and the testkit will use the provided setting.It will create an
pekko.actor.typed.ActorSystemwith this name, e.g. threads will include the name.It will also used the provided customConfig provided to create the
ActorSystem, and provided setting.When the test has completed you should terminate the
ActorSystemand the testkit withshutdownTestKit(). -
shutdown
Shutdown the givenpekko.actor.typed.ActorSystemand block until it shuts down, if more time thanTestKitSettings.DefaultActorSystemShutdownTimeoutpasses an exception is thrown -
shutdown
public static void shutdown(ActorSystem<?> system, scala.concurrent.duration.Duration timeout, boolean throwIfShutdownFails) Shutdown the givenpekko.actor.typed.ActorSystemand block until it shuts down or thedurationhits. If the timeout hitsverifySystemShutdowndecides -
shutdown$default$3
public static boolean shutdown$default$3() -
ApplicationTestConfig
public static com.typesafe.config.Config ApplicationTestConfig()Config loaded fromapplication-test.conf, which is used if no specific config is given. -
internalSystem
-
name
-
config
public com.typesafe.config.Config config() -
testKitSettings
-
system
INTERNAL API -
timeout
-
scheduler
-
shutdownTestKit
public void shutdownTestKit() -
spawn
Spawn the given behavior. This is created as a child of the test kit guardian -
spawn
Spawn the given behavior. This is created as a child of the test kit guardian -
spawn
Spawn the given behavior. This is created as a child of the test kit guardian -
spawn
Spawn the given behavior. This is created as a child of the test kit guardian -
stop
Stop the actor under test and wait until it terminates. It can only be used for actors that were spawned by thisActorTestKit. Other actors will not be stopped by this method. -
stop$default$2
public <T> scala.concurrent.duration.FiniteDuration stop$default$2() -
createTestProbe
Shortcut for creating a new test probe for the testkit actor system -
createTestProbe
Shortcut for creating a new named test probe for the testkit actor system -
createUnhandledMessageProbe
- Returns:
- A test probe that is subscribed to unhandled messages from the system event bus. Subscription will be completed and verified so any unhandled message after it will be caught by the probe.
-
createDeadLetterProbe
- Returns:
- A test probe that is subscribed to dead letters from the system event bus. Subscription will be completed and verified so any dead letter after it will be caught by the probe.
-
createDroppedMessageProbe
- Returns:
- A test probe that is subscribed to dropped letters from the system event bus. Subscription will be completed and verified so any dropped letter after it will be caught by the probe.
-
serializationTestKit
Additional testing utilities for serialization.
-