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.
To run a test from the command line, run adb shell to start a command line shell on your device or emulator. Inside that shell you can interact with the activity manager using the am command and use its instrument subcommand to run your tests.
In order to run the instrumentation test, you need to select Android Instrumentation Tests under Test Artifact in the Build Variants window. You should see the project structure change and the classes under the androidTest folder should now be visible.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With