Skip to content

joda/akka-expect

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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])
  }

About

Expect mimic for testing Akka actors

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages