Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Expect mimic for testing Akka actors

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 project
Octocat-spinner-32 src
Octocat-spinner-32 .gitignore
Octocat-spinner-32 README.md
README.md

akka-expect

akka-expect is an expect mimic to facilitate easy testing of Akka actors. Following are a few examples, please see ExpectActorSpec for the full spec.

beforeEach

In order to demonstrate the features of akka-expect we need the following two actors:

  class EchoService extends Actor {
    override def receive = {
      case msg => self reply msg
    }
  }

  class DiscardService extends Actor {
    override def receive = {
      case msg =>
    }
  }

The expectActor is created using

val expectActor = actorOf[ExpectActor].start

In order to avoid specifying the expectActor as a sender every time, we declare it implicit:

implicit val senderOption = Option(expectActor)

expect

  "ExpectActor" should "enable synchronous assertion of specific messages" in {
    echoService ! "hello"
    expectActor ? "hello"
  }

expectNo

  it should "enable explicit assertion of specific messages that are not expected" in {
    echoService ! "hola"
    expectActor ? noneOf("hello")
    expectActor ? "hola"
  }

expectNothing

  it should "enable explicit assertion of no messages of any kind" in {
    discardService ! "hello"
    expectActor ? nothing
  }

expectMultiple (ordered)

  it should "enable assertion of multiple messages received in specific order" in {
    echoService ! "hello"
    echoService ! "world"
    expectActor ? inOrder("hello", "world")
  }

expectMultiple (unordered)

  it should "enable assertion of multiple messages received in any order" in {
    echoService ! "hello"
    echoService ! "world"
    expectActor ? anyOrder("world", "hello")
  }

expectAny

  it should "enable assertion of messages of a specific class" in {
    echoService ! "hello"
    expectActor ? anyOf(classOf[String])
  }
Something went wrong with that request. Please try again.