How to get Android Logging output displayed using JUnit tests (using built-in JUnit without emulator)

I use JUnit 4 to write tests for Android (these tests do not use the emulator and work as my own tests). In my code, I use SL4J for logging, however, when I run the unit tests, I cannot see any log output. For example, expressions such as:

  private static final Logger logger = LoggerFactory.getLogger(AClass.class);
  logger.warn("log output not visible in unit test");

Any ideas on whether it is possible to access the logger output in unit tests?

Hello,

+4
source share
1 answer

I have answered this before, but I cannot find the link to the answer right now.

Here is the Android gradle plugin:

android {
  // ...

  testOptions.unitTests.all {
    testLogging {
      events 'passed', 'skipped', 'failed', 'standardOut', 'standardError'
    }
  }
}

, gradle:

tasks.withType(Test) {
    testLogging {
        exceptionFormat 'full'
        showCauses true
        showExceptions true
        showStackTraces true
        showStandardStreams true
    }
}
+4

Source: https://habr.com/ru/post/1616904/


All Articles