BottomNavigationItemView
实现了具有setChecked()
方法的ItemView
接口。如何断言BottomNavigationItemView是用Espresso检查的?
我试图用Espresso声明一个itemView被选中,但是我得到了同样的错误,无论我的期望值是多少,isChecked()
或isNotChecked()
。
我的测试:
ViewInteraction buttonHome = onView(
allOf(withId(R.id.bottomHome),
childAtPosition(
childAtPosition(
withId(R.id.bottom_navigation),
0),
0),
isDisplayed()));
buttonHome.check(matches(isNotChecked()));
错误消息
android.support.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: 'with checkbox state: is <true>' doesn't match the selected view.
Expected: with checkbox state: is <true>
Got: "BottomNavigationItemView{id=2131493015, res-name=bottomHome, visibility=VISIBLE, width=360, height=168, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2}"
我怎么能断言BottomNavigationItemView
是BottomNavigationView
当前选定的项目?
也许在这种情况下尝试使用经典的JUnit断言而不是Espresso断言。我的意思是:'assertEquals(((BottomNavigationItemView)findViewById(R.id.bottomHome))。isChecked(),true);' – piotrek1543