Android Test Case - how to view output?

AndroidUnit Testing

Android Problem Overview


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?

Android Solutions


Solution 1 - Android

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

Solution 2 - Android

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

Solution 3 - Android

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

Solution 4 - Android

In my case ,

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

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

Solution 5 - Android

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.

Solution 6 - Android

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJack BeNimbleView Question on Stackoverflow
Solution 1 - AndroidJorge CasariegoView Answer on Stackoverflow
Solution 2 - AndroidDiego Torres MilanoView Answer on Stackoverflow
Solution 3 - AndroidtminView Answer on Stackoverflow
Solution 4 - AndroidNabziView Answer on Stackoverflow
Solution 5 - AndroidJoshua PinterView Answer on Stackoverflow
Solution 6 - AndroidChloeView Answer on Stackoverflow