Akka actors unit testing with Scala
I'm fairly new to Scala so please be gentle.
In the app I'm building, I'm using Akka actors and I want to write some unit tests. I came across this official documentation for writing unit tests for Akka actors
but I couldn't understand exactly how it should work. In particular,
val actorRef = TestActorRef(new MyActor)
// hypothetical message stimulating a '42' answer
val future = actorRef ? Say42
val Success(result: Int) = future.value.get
result must be(42)
When I try that, I get not found: value Success, which is not surprising.
I then found this example of how to test Scala actors
, which admittedly is possibly old, but it is easy to understand and closer to what I normal use when I want to use Futures, and most importantly works. It does require me to declare a few implicits like the ActorSystem, timeout and such, which doesn't seem to be the case with the official way...
If possible, I'd like to use the method proposed by the official documentation, so I would appreciate it if someone help me understand how it works (in particular the Success bit) and how to use it.
I'm fairly new to Scala so please be gentle.
In the app I'm building, I'm using Akka actors and I want to write some unit tests. I came across this official documentation for writing unit tests for Akka actors
but I couldn't understand exactly how it should work. In particular,
val actorRef = TestActorRef(new MyActor)
// hypothetical message stimulating a '42' answer
val future = actorRef ? Say42
val Success(result: Int) = future.value.get
result must be(42)
When I try that, I get not found: value Success, which is not surprising.
I then found this example of how to test Scala actors
, which admittedly is possibly old, but it is easy to understand and closer to what I normal use when I want to use Futures, and most importantly works. It does require me to declare a few implicits like the ActorSystem, timeout and such, which doesn't seem to be the case with the official way...
If possible, I'd like to use the method proposed by the official documentation, so I would appreciate it if someone help me understand how it works (in particular the Success bit) and how to use it.
No comments:
Post a Comment