Question

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

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?

 21  15433  21
1 Jan 1970

Solution

 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
.
.
.
2011-10-28

Solution

 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");
2011-05-12