Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Android Logging Output Displayed with JUnit Tests (using native JUnit w/o Emulator)

I am using JUnit 4 to write Android test cases (these tests are not using the Emulator and are running as native tests). Within my code I use SL4J for logging, however when I run the unit tests, I am not able to see any of the logging output. For example statements such as the following:

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

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

Regards,

like image 810
user3521637 Avatar asked Nov 22 '15 01:11

user3521637


1 Answers

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

Here is the Android gradle plugin solution:

android {
  // ...

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

Here is the solution I use for any Gradle test:

tasks.withType(Test) {
    testLogging {
        exceptionFormat 'full'
        showCauses true
        showExceptions true
        showStackTraces true
        showStandardStreams true
    }
}
like image 94
Jared Burrows Avatar answered Nov 14 '22 23:11

Jared Burrows