首页 > 解决方案 > 如何在评级栏上进行仪器测试

问题描述

我尝试使用以下代码在 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 上进行正确的仪器测试?

标签: android-studiotestingratingbar

解决方案


推荐阅读