You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Firebase测试--test-targets参数能否指定多个自定义注解?

如何在Firebase测试中指定多个自定义注解作为测试目标?

问题背景

我定义了两个自定义注解:

@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
annotation class MyAnnotationOne

@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
annotation class MyAnnotationTwo

并为测试用例分别标记了@MyAnnotationOne和@MyAnnotationTwo。单独指定一个注解的Firebase命令可以正常运行:

--test-targets="annotation com.foo.MyAnnotationOne" \

但尝试用逗号分隔多个注解时没有测试用例运行:

--test-targets="annotation com.foo.MyAnnotationOne,annotation com.foo.MyAnnotationTwo" \

解决方案

Firebase测试支持指定多个自定义注解作为测试目标,问题出在语法错误——不能用逗号分隔多个注解规则,正确的写法有两种:

方式1:拆分多个--test-targets参数

将每个注解过滤器作为独立的参数传递:

gcloud firebase test android run \
  --test-targets="annotation com.foo.MyAnnotationOne" \
  --test-targets="annotation com.foo.MyAnnotationTwo"

方式2:同一引号内用空格分隔多个规则

在同一个--test-targets参数值中,用空格分隔不同的注解过滤器:

gcloud firebase test android run \
  --test-targets="annotation com.foo.MyAnnotationOne annotation com.foo.MyAnnotationTwo"

原理说明

--test-targets参数支持多个测试过滤器,多个规则之间是逻辑或的关系:只要测试用例匹配其中任意一个注解,就会被执行。你之前用逗号分隔的写法会被Firebase解析成一个完整的、不符合规则的过滤器表达式,导致无法匹配任何测试用例,因此没有测试被运行。

内容的提问来源于stack exchange,提问作者Boyana Staneva

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 05:40:01