MoM*_*oMo 10 printing testing logging android cmd
我在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.
我想@MoMo做了类似的事情,在命令提示符窗口中输入日志输出:
在您的测试类中定义一个函数:
private void out(String str) {
Bundle b = new Bundle();
b.putString(Instrumentation.REPORT_KEY_STREAMRESULT, "\n" + str);
InstrumentationRegistry.getInstrumentation().sendStatus(0, b);
}
Run Code Online (Sandbox Code Playgroud)
然后只需在@Test函数中使用它:
out("Some message...");
Run Code Online (Sandbox Code Playgroud)
在带有adb shell am instrument ...的命令提示符窗口中运行测试时会出现输出,但它不会显示在Android Studio的"运行"窗口中.它以某种方式过滤测试运行的输出,我找不到修改此过滤器的设置.
| 归档时间: |
|
| 查看次数: |
1253 次 |
| 最近记录: |