You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

如何通过gcloud命令在Firebase Test Lab中运行单个Android测试?

如何使用gcloud命令在Firebase Test Lab中运行单个Android测试用例?

我之前也踩过这个坑,问题出在你对--test-targets参数的语法使用上——你把测试方法名和类名用点连接了,导致系统把整个字符串当成了类名去查找,自然找不到对应的类。

正确的语法格式

要运行单个测试方法,需要用#来分隔测试类和方法名,具体格式如下:

--test-targets "class 你的测试类全限定名#测试方法名"

修正后的完整命令

把你的命令里的--test-targets参数改成下面这样就能正常运行了:

gcloud firebase test android run \
 --type instrumentation \
 --project locuslabs-android-sdk \
 --app app/build/outputs/apk/debug/app-debug.apk \
 --test app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk \
 --device model=Pixel2,version=27,locale=en_US,orientation=portrait \
 --verbosity debug \
 --test-targets "class com.example.firebasetestlabplayground.ExampleInstrumentedTest#test002"

扩展用法(额外参考)

除了单个测试方法,这个参数还支持其他几种常用的测试范围:

  • 运行某个测试类的所有用例:
    --test-targets "class com.example.firebasetestlabplayground.ExampleInstrumentedTest"
    
  • 运行多个指定测试方法:
    --test-targets "class com.example.YourTestClass#testMethod1,class com.example.YourTestClass#testMethod2"
    
  • 运行某个包下的所有测试:
    --test-targets "package com.example.firebasetestlabplayground"
    

你之前报错的原因

你之前用.连接类和方法名,系统会尝试加载名为com.example.firebasetestlabplayground.ExampleInstrumentedTest.test002的类,这显然不是一个合法的类名,所以才抛出了ClassNotFoundException

内容的提问来源于stack exchange,提问作者Michael Osofsky

火山引擎 最新活动