Android Instrumented Unit Test: Print Output Log

Oct 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

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.