从CLI测试后如何获取gcloud Firebase测试实验室Android Espresso结果?
我们将Travis CI与Fastlane结合使用,进行自动化构建和夜间UI浓缩咖啡测试。对于仪器测试,我们尝试使用Firebase测试实验室,使用gcloud命令行工具 我试图以一种易于使用的格式获取测试结果,以便我可以在内部向Slack报告,例如有多少测试通过或失败,以及哪些测试通过。从CLI测试后如何获取gcloud Firebase测试实验室Android Espresso结果?,android,firebase,travis-ci,gcloud,firebase-test-lab,Android,Firebase,Travis Ci,Gcloud,Firebase Test Lab,我们将Travis CI与Fastlane结合使用,进行自动化构建和夜间UI浓缩咖啡测试。对于仪器测试,我们尝试使用Firebase测试实验室,使用gcloud命令行工具 我试图以一种易于使用的格式获取测试结果,以便我可以在内部向Slack报告,例如有多少测试通过或失败,以及哪些测试通过。 ./google-cloud-sdk/bin/gcloud beta firebase test android run \ --type instrumentation \ --app ourapp/app
./google-cloud-sdk/bin/gcloud beta firebase test android run \
--type instrumentation \
--app ourapp/app/build/outputs/apk/mock/debug/app-mock-debug-local.apk \
--test ourapp/app/build/outputs/apk/androidTest/mock/debug/ourapp-mock-debug-androidTest.apk \
--device-ids hammerhead \
--os-version-ids 22 \
--locales en \
--orientations portrait \
--project ourappgoogleprojectid \
--timeout 15m
这一切都会很好地执行测试,并打印两个指向Google云存储桶中原始结果的链接,其中包含一些随机链接和一些如下日志:
Raw results will be stored in your GCS bucket at [https://console.developers.google.com/storage/browser/test-lab-vx5ak1y4tt3sw-yrzyhxjh4r1r6/]
13:25:59 Test is Pending
13:26:06 Starting attempt 1
13:26:06 Test is Running
13:26:46 Logging into the device
13:26:53 Installing APK: com.ourcompany.ourapp.debug
13:27:13 Installing APK: com.ourcompany.ourapp.test
13:27:33 Running instrumentation test. Package: com.ourcompany.ourapp.test testrunner: android.support.test.runner.AndroidJUnitRunner orchestrator: false options: []
13:34:34 Instrumentation test has finished
13:34:34 Generating video
13:34:41 Retrieving performance samples
13:35:00 Retrieving test artifacts
13:35:13 Retrieving any crash results
13:35:20 Retrieving logcat
13:35:53 Done. Test time=416 (secs)
13:36:00 Test is Finished
Instrumentation testing complete.
[
{
"axis_value": "hammerhead-21-en-portrait",
"outcome": "Failed",
"test_details": "5 test cases failed, 187 passed"
}
]
然后最后打印出我最感兴趣的内容:
┌─────────┬───────────────────────────┬──────────────────────┐
│ OUTCOME │ TEST_AXIS_VALUE │ TEST_DETAILS │
├─────────┼───────────────────────────┼──────────────────────┤
│ Passed │ hammerhead-22-en-portrait │ 60 test cases passed │
└─────────┴───────────────────────────┴──────────────────────┘
但是,没有其他东西可以让我对结果做出一个好的、可行的、快速的总结
我想我只能这样做:
Grep/awk/sed/它在输出中打印的bucket url。但那个url有一些随机ID之类的东西。然后从Travis中的bash脚本中,尝试下载该存储桶中的xml文件。但是所有的测试结果xml都在各自的文件夹中,以测试运行的设备命名。例如hammerhead-22-en-grait
。为了得到一个简单的测试摘要,这真是一件麻烦事。我所需要的只是上面打印的表格中的信息
是否缺少任何gcloud
命令选项?文件很糟糕。我希望可以选择立即下载适当的xml文件,或者使用适当的信息或其他内容设置环境变量
或者有没有一种方法可以轻松地从该表中提取值
编辑:
我刚刚发现Android Studio支持设置运行配置,自动构建、上传apk并在Firebase测试实验室矩阵上执行测试。然后,在Android Studio的“运行”选项卡中会得到一份不错的测试报告。从这里可以将这些测试结果导出为HTML或XML。XML正是我想要的。有人知道安卓Studio使用什么工具来做这件事,或者我如何使用命令行工具来做同样的事情吗?这里有一些技巧可以帮助您完成这项工作 关于结果路径中的默认随机ID:您可以通过使用
--results dir=my/results/path
标志对该路径进行更多控制(只需确保为运行的每个测试选择一个唯一的值)。您还可以指定--results bucket=gs://my bucket
,以控制存储测试结果的顶级bucket。请注意,如果您使用--results bucket,您需要一个GCP计费帐户,并将为您的结果支付云存储费用;您可以免费使用提供的默认存储桶,并且它的路径在脚本编写时应该保持稳定
gcloud firebase test android run
命令的所有标志选项都是或通过CLI向任何gcloud命令或命令片段添加--help
使用这些标志,您应该能够使用gsutil cp
命令直接从原始结果中获取junit.xml文件
如果您想直接解析gcloud输出,那么知道将测试结果表打印到stdout,同时将所有状态更新打印到stderr是很有用的。因此,您可以通过向命令中添加1>results.out
来隔离结果。您还可以通过--format=
标志(可在所有gcloud命令上使用)控制输出表的格式。例如,如果将--format=json 1>results.out
添加到上面的命令中,则输出将如下所示:
Raw results will be stored in your GCS bucket at [https://console.developers.google.com/storage/browser/test-lab-vx5ak1y4tt3sw-yrzyhxjh4r1r6/]
13:25:59 Test is Pending
13:26:06 Starting attempt 1
13:26:06 Test is Running
13:26:46 Logging into the device
13:26:53 Installing APK: com.ourcompany.ourapp.debug
13:27:13 Installing APK: com.ourcompany.ourapp.test
13:27:33 Running instrumentation test. Package: com.ourcompany.ourapp.test testrunner: android.support.test.runner.AndroidJUnitRunner orchestrator: false options: []
13:34:34 Instrumentation test has finished
13:34:34 Generating video
13:34:41 Retrieving performance samples
13:35:00 Retrieving test artifacts
13:35:13 Retrieving any crash results
13:35:20 Retrieving logcat
13:35:53 Done. Test time=416 (secs)
13:36:00 Test is Finished
Instrumentation testing complete.
[
{
"axis_value": "hammerhead-21-en-portrait",
"outcome": "Failed",
"test_details": "5 test cases failed, 187 passed"
}
]
通过运行
gcloud topic formats
Perfect,您可以了解有关gcloud格式的更多信息!这正是我所需要的,特别是因为我们没有为这个项目的Firebase设置计费帐户。我知道我一定漏掉了什么东西,--format
标志起了作用,谢谢!