【问题标题】:How to get logs when running android tests with ADB使用 ADB 运行 android 测试时如何获取日志
【发布时间】:2021-07-26 05:38:33
【问题描述】:

我使用 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 窗口中)。

【问题讨论】:

    标签: android testing logging adb logcat


    【解决方案1】:

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

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

    【讨论】:

    • 不是这个原因。我的脚本中有这个。问题是,测试完成后,logcat 命令不会传递应用程序的日志。只有系统日志可用,这没有用。当我运行测试并并行启动 logcat 时,我可以看到相关日志。但是当测试完成并启动 logcat 时,应用程序的特定日志不再可用。
    • 所以也许它只是与 logcat 缓冲区有关。您要求 logcat 为时已晚,无法获取应用程序日志。您可以尝试使用以下命令增加 logcat 缓冲区:adb logcat -g 12M
    • 嗯。现在,我认为日志在那里。我没有看到它们,因为 logcat 输出包含很多其他日志,并且没有显示包名称。所以非常混乱。我试过这个:“adb -d logcat com.mypackagename:I”但还有很多其他日志我不需要。你知道我如何使用 logcat 只获取我的应用程序的日志以及如何显示包名吗?
    猜你喜欢
    • 2018-03-11
    • 1970-01-01
    • 2015-01-11
    • 1970-01-01
    • 1970-01-01
    • 2022-09-28
    • 1970-01-01
    • 1970-01-01
    • 2021-11-07
    相关资源
    最近更新 更多