akka actor testing using play

2019-02-18 02:09发布

问题:

I want to test my akka actor. Is it possible to test every case of receive function?

def receive = {

  case msg: String =>
    println("SUCCESS" + msg)

  case user: VerifyIfUserExistActor =>
    implicit val timeout = Timeout(30 seconds)
    val future = platActor ? user
    val result = Await.result(future, timeout.duration).asInstanceOf[Users]
    sender ! result

  case ottDetails: OttDetails =>
    println("SUCCESS" + ottDetails)

}

回答1:

Yes, if you want to test if you are sending a successful message and just want to see that your actor system works. You can use

case _ => println("sending message success")