我有一个Android应用程序,我正在尝试做一些基本的测试。
public class TimePickerTest {
@Rule
public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(MainActivity.class);
@Test
public void timePickerReturnsATime() {
onView(withId(R.id.timePickerLayout)).perform(click());
当我运行它时,我得到“层次结构中找不到匹配的视图”。它列出了一个庞大的层次结构列表。开头看起来像这样:
View Hierarchy:
+>DecorView{id=-1, visibility=VISIBLE, width=1080, height=1920, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, 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} |
+->LinearLayout{id=-1, visibility=VISIBLE, width=1080, height=1776, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, 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} |
+-->ViewStub{id=16909225, res-name=action_mode_bar_stub, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0}
它有大量的观点很难识别,身份证号码对我来说没有意义。如何访问我想要的视图?我是否必须从主屏幕开始并导航到我想要的视图?
我设法访问的唯一视图是fragment_container,但我无法弄清楚从哪里去。