Where does LogCat's Log.x() output go when running Android JUnit tests?
Asked Answered
O

4

21

I noticed that when testing plain Java classes via test classes derived from TestCase and AndroidTestCase, LogCat output disappears.

Is it possible to still capture the output of these messages? or my only recourse is to use the much more sluggish ActivityInstrumentationTestCase2<> as a base class?

Opposition answered 12/5, 2011 at 18:15 Comment(0)
A
20

I had similar issue... The point here is that the logcat view available in Eclipse does not show anything when running the project in Android Junit mode. At least, in the Android 2.1 that I was using, that's the behavior.

You can workaround this issue by checking the logcat from command line (terminal window):

# check the device name you are using
# It gives something like this:
$ ./adb devices
List of devices attached 
emulator-5554   device

# open logcat of the device
$ ./adb -s emulator-5554 logcat
D/AndroidRuntime(  943): 
D/AndroidRuntime(  943): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
D/AndroidRuntime(  943): CheckJNI is ON
.
.
.
Add answered 28/10, 2011 at 12:23 Comment(0)
L
7

Both of these statements produce log in logcat:

    android.util.Log.d(TAG, "This is Log.d");
    System.out.println("This is System.out.println");
Logsdon answered 12/5, 2011 at 21:49 Comment(2)
Yes I know but that is not what I asked. My problem is that I would like to see the same LogCat output while running JUnit.Opposition
I meant exactly that. This is how you log from your tests. Are you using android test runner or something else ? This could be your problem, I guess.Logsdon
R
3

Just for anyone using Android Studio. You can open the Android DDMS tool window (Cmd + 6) and turn off any filters using the dropdown box in the top right. It seems to use app:com.your.package.name as a default, which filters test output.

Repairman answered 3/12, 2014 at 4:11 Comment(0)
T
2

Simply using Log.v("MyIdentifier","MyMessage") statements seems to log everything for me, both from the Unit test classes themselves and from my Android application under test.

This info may help someone using Android jUnit for the first time:

Android jUnit testing will only actually start an activity when getActivity() is called from within a test class. If get Activity is not called you will not see the results of any of the logging calls you have written in for example onCreate or onResume. There seems to be an exception to this rule though when the Activity marked as "Main" and "Launcher" in the Android Manifest is under test.

Thunderpeal answered 5/4, 2012 at 9:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.