4
votes

I'm writing unit tests for Akka actors and want to verify log entries; e.g. test xyz wrote to the error category. (You know, let's say I send an actor a message via ! instead of ?.)

In the actor, I'll write to log for error or info or debug, etc. case depending on result of the message handled by "receive".

For akka 1.2 or 1.3, how should I go about this? Example: add a new listener to EventHandler? Other ideas?

Thanks in advance, Todd

1

1 Answers

4
votes

John has the basics covered in his answer already (I’d pipe the message to the testActor instead of using a TestLatch, but that is a matter of taste). I know it does not fit your requirements, but maybe the following can lure you into Akka 2.0?

EventFilter.error(message = "some message", occurrences = 1) intercept {
  // do something which should trigger such a log message
}

These facilities come from the akka-testkit, specifically akka.testkit.TestEventListener and akka.testkit.EventFilter. The code shown above will wait for up to three seconds (configurable in “akka.test.filter-leeway”) for the message to appear and give an informative error message if that does not happen.