【问题标题】:how to print logs in cmd console while execute android instrument test执行android仪器测试时如何在cmd控制台中打印日志
【发布时间】:2016-07-25 08:14:03
【问题描述】:

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

我想在运行测试时在cmd中打印日志,谁能告诉我如何编写代码来打印日志?我绑定了system.out.println("xx")和Log.i("xx","xx"),但是没用。

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

【问题讨论】:

标签: android testing logging printing cmd


【解决方案1】:

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

在你的测试类中定义一个函数:

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

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

out("Some message...");

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-04-23
    • 1970-01-01
    • 2015-10-03
    • 1970-01-01
    • 1970-01-01
    • 2021-03-01
    • 2016-12-20
    • 1970-01-01
    相关资源
    最近更新 更多