I have the following trait
trait MyTrait{
def printHelloWorld(){
println("hello world")
}
}
case object SayHello
class MyActor extends Actor with MyTrait{
def recieve = {
case SayHello => printHelloWorld
}
}
Now I'm trying to create Unit Test which test then Say Hello Object invokes printing hello message
"My Actor" should{
"println hello msg if SayHello sent" in{
val myTraitMock = mock[MyTrait]
val myActor = system.actorOf(Props(new MyActor))
myActor ! SayHello
Thread.sleep(500)
there was atLeastOne(myTraitMock).printHelloMessage
}
}
However this unit test is always green. Even if I replace this method with simple println method.
Is there any other method to test such case?
How about this:
In general for actors, I am not a fan of above like testing. Akka Test-kit is brilliant. I would highly recommend looking at it.
In which I would do :