Testing

You are viewing the documentation for the new actor APIs, to view the Akka Classic documentation, see Classic Testing.

Module info

To use Actor TestKit add the module to your project:

sbt
val AkkaVersion = "2.6.10"
libraryDependencies += "com.typesafe.akka" %% "akka-actor-testkit-typed" % AkkaVersion % Test
Maven
<properties>
  <akka.version>2.6.10</akka.version>
  <scala.binary.version>2.13</scala.binary.version>
</properties>
<dependency>
  <groupId>com.typesafe.akka</groupId>
  <artifactId>akka-actor-testkit-typed_${scala.binary.version}</artifactId>
  <version>${akka.version}</version>
  <scope>test</scope>
</dependency>
Gradle
versions += [
  AkkaVersion: "2.6.10",
  ScalaBinary: "2.13"
]
dependencies {
  test group: 'com.typesafe.akka', name: "akka-actor-testkit-typed_${versions.ScalaBinary}", version: versions.AkkaVersion
}

We recommend using Akka TestKit with ScalaTest:

sbt
libraryDependencies += "org.scalatest" %% "scalatest" % "3.1.4" % Test
Maven
<properties>
  <scala.binary.version>2.13</scala.binary.version>
</properties>
<dependency>
  <groupId>org.scalatest</groupId>
  <artifactId>scalatest_${scala.binary.version}</artifactId>
  <version>3.1.4</version>
  <scope>test</scope>
</dependency>
Gradle
versions += [
  ScalaBinary: "2.13"
]
dependencies {
  test group: 'org.scalatest', name: "scalatest_${versions.ScalaBinary}", version: '3.1.4'
}
Project Info: Akka Actor Testkit (typed)
Artifact
com.typesafe.akka
akka-actor-testkit-typed
2.6.10
JDK versions
Adopt OpenJDK 8
Adopt OpenJDK 11
Scala versions2.12.11, 2.13.3
JPMS module nameakka.actor.testkit.typed
License
Readiness level
Since 2.6.0, 2019-11-06
Home pagehttps://akka.io/
API documentation
Forums
Release notesakka.io blog
IssuesGithub issues
Sourceshttps://github.com/akka/akka

Introduction

Testing can either be done asynchronously using a real ActorSystemActorSystem or synchronously on the testing thread using the BehaviorTestKitBehaviorTestKit.

For testing logic in a BehaviorBehavior in isolation synchronous testing is preferred, but the features that can be tested are limited. For testing interactions between multiple actors a more realistic asynchronous test is preferred.

Those two testing approaches are described in:

Found an error in this documentation? The source code for this page can be found here. Please feel free to edit and contribute a pull request.