Testing

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

Module info

To use Actor TestKit add the module to your project:

sbt
val PekkoVersion = "1.1.2"
libraryDependencies += "org.apache.pekko" %% "pekko-actor-testkit-typed" % PekkoVersion % Test
Maven
<properties>
  <scala.binary.version>2.13</scala.binary.version>
</properties>
<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.apache.pekko</groupId>
      <artifactId>pekko-bom_${scala.binary.version}</artifactId>
      <version>1.1.2</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>
<dependencies>
  <dependency>
    <groupId>org.apache.pekko</groupId>
    <artifactId>pekko-actor-testkit-typed_${scala.binary.version}</artifactId>
    <scope>test</scope>
  </dependency>
</dependencies>
Gradle
def versions = [
  ScalaBinary: "2.13"
]
dependencies {
  implementation platform("org.apache.pekko:pekko-bom_${versions.ScalaBinary}:1.1.2")

  testImplementation "org.apache.pekko:pekko-actor-testkit-typed_${versions.ScalaBinary}"
}

We recommend using Pekko TestKit with ScalaTest:

sbt
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.19" % Test
Maven
<properties>
  <scala.binary.version>2.13</scala.binary.version>
</properties>
<dependencies>
  <dependency>
    <groupId>org.scalatest</groupId>
    <artifactId>scalatest_${scala.binary.version}</artifactId>
    <version>3.2.19</version>
    <scope>test</scope>
  </dependency>
</dependencies>
Gradle
def versions = [
  ScalaBinary: "2.13"
]
dependencies {
  testImplementation "org.scalatest:scalatest_${versions.ScalaBinary}:3.2.19"
}
Project Info: Pekko Actor Testkit (typed)
Artifact
org.apache.pekko
pekko-actor-testkit-typed
1.1.2
JDK versions
OpenJDK 8
OpenJDK 11
OpenJDK 17
OpenJDK 21
Scala versions2.13.14, 2.12.20, 3.3.4
JPMS module namepekko.actor.testkit.typed
License
Home pagehttps://pekko.apache.org/
API documentation
Forums
Release notesRelease Notes
IssuesGithub issues
Sourceshttps://github.com/apache/pekko

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: