【发布时间】:2022-06-15 17:53:17
【问题描述】:
我有一个设置背景颜色的组合,我想测试一下。
@Composable
fun MyComposableButton(
enabledColor: Color,
disableColor: Color,
isEnabled: Boolean = true,
) {
val buttonBackgroundColor = if (enabled) enabledColor else disableColor
Button(
...
enabled = enabled,
colors = ButtonDefaults.textButtonColors(
backgroundColor = buttonBackgroundColor
)
) { ... }
}
我希望编写如下测试:verifyEnabledBackgroundColor 和 verifyDisabledBakcgroundColor。
我在撰写测试中找不到任何直接可用的断言,当我尝试创建自己的断言时,我发现SemanticMatcther 使用SemanticNode,但构造函数是最新的内部的,所以不行.
我尝试mock Color 但我做不到,根据this answer 需要高 API 级别,这对我的项目来说是不行的。
如何测试设置可组合的背景颜色?
【问题讨论】:
标签: android android-jetpack-compose android-testing