How to print logs in cmd console when running toolkit test for Android

I open cmd on a Windows system and then type " adb shell am instrument -w com.demo.uia.test/android.support.test.runner.AndroidJUnitRunner " to run the Android test.

I want to print the log in cmd while running the test, can someone tell me how to write code to print the log? I bound system.out.println("xx") and Log.i("xx","xx") , but this is useless.

I want to show the log in cmd line and not in logcat. I solved the problem now, use sendStatus api.

+7
android cmd logging printing testing
source share
1 answer

I think @MoMo did something like this to have log output in the command window:

In your test class, define a function:

 private void out(String str) { Bundle b = new Bundle(); b.putString(Instrumentation.REPORT_KEY_STREAMRESULT, "\n" + str); InstrumentationRegistry.getInstrumentation().sendStatus(0, b); } 

Then just use it in the @Test functions, for example:

 out("Some message..."); 

The output appears when you run the test in the command window using the adb shell am ... tool, but it does not appear in the Run window of Android Studio. It somehow filters the output of the test runs, and I cannot find a parameter to change this filter.

+2
source share

All Articles