android-studio - 如何在评级栏上进行仪器测试
问题描述
我尝试使用以下代码在 ratingbar 上进行仪器测试
@Test
fun loadDetailMovie() {
onView(withId(R.id.ratingBar)).check(matches(isDisplayed()))
onView(withId(R.id.ratingBar)).check(matches(withText(dummyMovie[0].getRating().toString())))
}
但结果失败了
androidx.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: 'with text: is "4.3"' 与所选视图不匹配。预期:带文本:是“4.3”得到:“AppCompatRatingBar{id=2131231024, res-name=ratingBar, visibility=VISIBLE, width=280, height=56, has-focus=false, has-focusable=false, has-窗口焦点 = 真,可点击 = 假,启用 = 真,焦点 = 假,焦点可 = 假,布局请求 = 假,选择 = 假,布局参数 = androidx。 constraintlayout.widget.ConstraintLayout$LayoutParams@7449c72, tag=null, root-is-layout-requested=false, has-input-connection=false, x=84.0, y=1033.0}"
如何在 ratingbar 上进行正确的仪器测试?
解决方案
推荐阅读
- javascript - 使用其他 div 滚动条在 div 内滚动
- macos - CATiledLayer 在 macOS 上渲染的图块太少
- iis - Blazor WASM 在 IIS 上发布 => 内存访问越界,加载 ICU 资产时出错
- javascript - 如何解构道具以传递给子组件?反应原生
- javascript - 在手机上用背景填充屏幕
- c# - 显示字符串异步延迟
- sabre - Sabre:GetReservation 的 REST 版本?
- mips - 交换字符串中的每两个字符并修复异常错误
- .net - 获取多个多边形的总边界框(使用 C# NetCore NetTopologySuite)
- android - 除非我的设备的位置和方向,否则我如何在相机前生成一个对象?