Class LogCapturing

  • All Implemented Interfaces:

    public final class LogCapturing
    extends java.lang.Object
    implements org.junit.rules.TestRule
    JUnit TestRule to make log lines appear only when the test failed.

    Use this in test by adding a public field annotated with @TestRule:

       @Rule public final LogCapturing logCapturing = new LogCapturing();

    Requires Logback and configuration like the following the logback-test.xml:

         <appender name="CapturingAppender" class="" />
         <logger name="" >
           <appender-ref ref="STDOUT"/>
         <root level="DEBUG">
             <appender-ref ref="CapturingAppender"/>
    • Constructor Summary

      Constructor Description
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      org.junit.runners.model.Statement apply​(org.junit.runners.model.Statement base, org.junit.runner.Description description)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • LogCapturing

        public LogCapturing()
    • Method Detail

      • apply

        public org.junit.runners.model.Statement apply​(org.junit.runners.model.Statement base,
                                                       org.junit.runner.Description description)
        Specified by:
        apply in interface org.junit.rules.TestRule