如何在执行android

如何在执行android

本文介绍了如何在执行android instrument test时在cmd控制台中打印日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows系统上打开一个cmd,然后输入"adb shell am instrument -w com.demo.uia.test/android.support.test.runner.AndroidJUnitRunner"以运行android测试.

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.

我想在运行测试时在cmd中打印日志,有人可以告诉我如何编写代码来打印日志吗?我把system.out.println("xx")Log.i("xx","xx")绑在一起了,但这没用.

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.

我想在cmd行而不是logcat中显示日志.我现在解决了问题,请使用sendStatus api.

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

推荐答案

我猜@MoMo做了这样的事情,以便在命令提示符窗口中记录日志输出:

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

然后只需在@Test函数中使用它即可,例如:

Then simply use it in @Test functions like:

out("Some message...");

使用 adb shell am instrument ... 在命令提示符窗口中运行测试时,将显示输出,但未在Android Studio的运行"窗口中显示.它以某种方式过滤了测试运行的输出,而我找不到修改此过滤器的设置.

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.

这篇关于如何在执行android instrument test时在cmd控制台中打印日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 15:39