Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Expect mimic for testing Akka actors
Scala
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
project Using SNAPSHOT as version until further notice
src
.gitignore
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.