59

I'm using AndroidTestCase for unit testing. I have a unit test which is failing, but I haven't figured out how to display output from it. For example, I don't see the values I print using Log.d or System.out.println in the console nor the logcat output.

How do I view the unit test console?

Willi Mentzel
  • 27,862
  • 20
  • 113
  • 121
Jack BeNimble
  • 35,733
  • 41
  • 130
  • 213

6 Answers6

51

With Android Studio 2.3.1, works using the old fashioned Java styled

System.out.println("Start Test");

Here you can see the output:

enter image description here

Jorge Casariego
  • 21,948
  • 6
  • 90
  • 97
32

You shoud see the Log.d() messages in logcat unless your test is crashing much before (i.e in the constructor).

Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134
7

In my case ,

System.out.println("Test") is working for JUnits tests,

Log.d("tag" , "Test") is working for AndroidJUnit tests(Instrumented)

Nabzi
  • 1,823
  • 1
  • 16
  • 26
6

Go to Debug --> Logcat. Make sure the LogLevel and Filter are correct as well.

See the screenshot from Android Studio 1.1.0

From Android Studio 1.1.0

tmin
  • 1,313
  • 13
  • 15
2

Just to be clear, if you're running an emulator you have to use adb logcat.

Also, make sure you're using the standard android.util.Log.d() to send your output.

Willi Mentzel
  • 27,862
  • 20
  • 113
  • 121
Joshua Pinter
  • 45,245
  • 23
  • 243
  • 245
  • 3
    Android Studio running Unit tests doesn't always connect to a device. In my case, there is no emulator or phone, robolectric tests are run entirely in the jre. – Mooing Duck Jan 20 '17 at 20:48
0

You probably disconnected the device/emulator and reconnected. You have to click on the device name again in the list in the Dalvik Debug Monitor for it to reload the logs and keep updating the output.

Chloe
  • 25,162
  • 40
  • 190
  • 357