Tuesday, 15 June 2010

java - How to intercept SLF4J logging via a JUnit test? -


By preventing logging (SLF 4J + lockback) in any way and receiving InputStream Is possible (or something else that can be read) through a JUnit test case ...?

You can create a custom appender

  public class testapper AppenderBase & Lt; LoggingEvent & gt; {Fixed list & lt; Logging event & gt; Incidents = New Arrestist & lt; & Gt; (); @ Override Protected Zero Attached (logging event e) {events.add (e); }}  

and configure log-test-test.xml for its use. Now we can check the logging incidents from our tests:

  @Test Public Zero Test () {... Assert.assertEquals (1, TestAppender.events.size ()); ...}  

No comments:

Post a Comment