Android: How to capture or display logging output when running gradle connectedCheck

Viewed 107

I am running gradle connectedCheck (i.e., tests for Android-specific code) and some of the tests print out some debugging information. The testing framework is JUnit.

I have tried various ways to output the debugging information, namely, System.out.println, android.util.Log.i, timber.log.Timber.i. However, in every case, the logging output is not displayed when I run gradle connectedCheck, gradle connectedCheck --info, or gradle connectedCheck --debug.

How can I obtain the logging output when running gradle connectedCheck, either on the console or output to a file? If output to a file, is there a way to ensure that the file is on the development host file system, and not on the Android emulator file system?

1 Answers

Did you find a solution to this?

When you are running instrumented tests, the test code is running on the device itself, so the system out is written to the device logs rather than the logs of the machine where you ran gradle. What I usually do then is after the test, run adb logcat and write the result to a file (e.g. adb logcat > logcat.txt, then press CTRL+C after a few seconds as it will continuously wait for more lines coming from the device). Then scan through the logcat looking for the statements that were written. It's not the most ideal solution and I'm still wondering if there's a better way.

Related