Android Instrumented Unit Test: Print Output Log

October 7, 2019

Just use Log.d.

@RunWith(AndroidJUnit4::class)
class LogTest {
    companion object {
        private const val TAG = "LogTest"
    }

    @Test
    fun logOutput() {
        Log.d(TAG, "Hello")
    }
}

Sometimes the Logcat tab is now showing any output, you could try one or more of the following.

  • Make sure Logcat tab is selected/active when running the test
  • Edit Configuration of the LogTest: Under Miscellaneous check Logcat -> Clear log before launch and maybe uncheck Installation Options -> Skip Installation if APK has not changed (you can check it again later after logcat is working)
  • Unplugged the USB cable and plug in again

NOTE: During Instrumented Unit Test run, the package name dropdown in Logcat tab is usually shown as [DEAD], but the log will show despite the [DEAD] status.

NOTE: System.out.println used to work in earlier version to print output in the Run tab, but this is no longer the case with Android Studio 3.5

This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.