16

I open a cmd on windows system, and then input "adb shell am instrument -w com.demo.uia.test/android.support.test.runner.AndroidJUnitRunner" to run android test.

I want to print log in the cmd while run the test, can anyone tell me how to write code to print log? I have tied system.out.println("xx") and Log.i("xx","xx"), but it's useless.

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

MoMo
  • 161
  • 1
  • 4

1 Answers1

10

I guess @MoMo did something like this to have logging output in command prompt 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 simply use it in @Test functions like:

out("Some message...");

The output appears when running the test in Command Prompt window with adb shell am instrument..., but it is not shown in Run window of Android Studio. It somehow filters the output of test runs, and I cannot find a setting to modify this filter.

gregko
  • 5,642
  • 9
  • 49
  • 76