微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用 ADB 运行 android 测试时如何获取日志

如何解决使用 ADB 运行 android 测试时如何获取日志

我使用 ADB 在多个设备上并行运行测试:

adb -s 11.11.11.111:5555 shell "CLAsspATH=$(pm path androidx.test.services) app_process / androidx.test.services.shellexecutor.ShellMain am instrument -r -w -e targetInstrumentation com.my.app.debug.test/androidx.test.runner.AndroidJUnitRunner -e clearPackageData true  -e numShards 2 -e shardindex 0 -e debug false androidx.test.orchestrator/androidx.test.orchestrator.AndroidTestorchestrator" &
adb -s 11.11.11.112:5555 shell "CLAsspATH=$(pm path androidx.test.services) app_process / androidx.test.services.shellexecutor.ShellMain am instrument -r -w -e targetInstrumentation com.my.app.debug.test/androidx.test.runner.AndroidJUnitRunner -e clearPackageData true  -e numShards 2 -e shardindex 1 -e debug false androidx.test.orchestrator/androidx.test.orchestrator.AndroidTestorchestrator" &
wait

如果测试失败,通常会显示错误消息/堆栈跟踪,但并非总是如此。因此,将应用程序的日志保存在文件中会很有帮助。 测试完成后,我尝试了以下命令:

adb -s 11.11.11.111:5555 logcat | grep "com.my.app.*" > app/build/reports/logcat.txt

但是该命令只保存文件中的系统日志,而不是我在 Android Studio 中运行测试时通常可以看到的日志(在 Android Studio 的 logcat 窗口中)。

解决方法

您可能只是忘记在 adb logcat 上添加 -s 11.11.11.11x:5555 选项。

==29783== Syscall param write(buf) points to uninitialised byte(s)
==29783==    at 0x4B691E7: write (write.c:26)
==29783==    by 0x10B85B: send_message(int,char*,int) (in /home/sofia/Desktop/syspro-2/travelMonitor)
==29783==    by 0x10A80F: main (in /home/sofia/Desktop/syspro-2/travelMonitor)
==29783==  Address 0x1ffefffc81 is on thread 1's stack
==29783==  in frame #1,created by send_message(int,int) (???:)
==29783== 
2:hi
2:hi
2:hi
2:hi
2:hi
==29783== 
==29783== HEAP SUMMARY:
==29783==     in use at exit: 0 bytes in 0 blocks
==29783==   total heap usage: 4 allocs,4 frees,138,864 bytes allocated
==29783== 
==29783== All heap blocks were freed -- no leaks are possible
==29783== 
==29783== Use --track-origins=yes to see where uninitialised values come from
==29783== For lists of detected and suppressed errors,rerun with: -s
==29783== ERROR SUMMARY: 5 errors from 1 contexts (suppressed: 0 from 0)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。