When writing tests, is it possible to verify messages that have been written by Play!'s logg开发者_StackOverflow中文版er class?
So for example, if the production code below is executed:
Logger.error("boo boo");
In my test, am I able to verify that the message boo boo
was written as an error to the logs?
The best way is to write your own log appender, which puts all data into a List. Then you can analyse the List at end of the test. Perhaps you can download such a logger from some sites. Another possibility is to use easymock to mock the appender, but I think this is more difficult, because you can't produce easily the expected LogEvent.
精彩评论