Question

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?

Was it helpful?

Solution

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
.
.
.

OTHER TIPS

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");

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top