Testing actors
For the testing of Actors that we create, we might consider few entities that are needed to be present. These entities might be:
- A test actor-system
- A
testActor
(the message sender) - The actor under testing (whose behavior we want to test)
- Assertions to be made in case of an actors expected message
Akka's test-kit
library provides us with all of these needed entities ready-made. We can use these to test our actors. Let's write a simple actor test case.
The expect case is to check if our GetPlayerInformationRequest
works fine:
package lsp import akka.actor.ActorSystem import akka.testkit.{ImplicitSender, TestKit} import lsp.SimpleActor.{GetPlayerInformationRequest, PlayerInformationResponse} import org.scalatest.{BeforeAndAfterAll, WordSpecLike} class SimpleActorSpec extends TestKit(ActorSystem("testActorSystem")) with ImplicitSender with WordSpecLike with BeforeAndAfterAll { override def afterAll(): Unit = super.afterAll() val players = List(Player("Cristiano...