Espresso testing with ExpandableListView

2019-02-24 20:00发布

问题:

I'm using espresso as my UI automation test. I want to create a matcher for ExpandableListView, since it sometimes goes of screen and its not good practice to call onView(withText("something")) on a view that has adapter bound to it. Can somebody show me how to create matcher for ExpandableListView?

回答1:

I don't know if this one would be useful, but:

 public static Matcher<Object> withListItemCheck(final <Type> check_value) {
    checkNotNull(check_value);
    return new BoundedMatcher<Object, <List_Item_class>>(<List_Item_class>.class) {
        private String m_message = "";

        @Override
        public void describeTo(Description d) {
            d.appendText(m_message);
        }

        @Override
        public boolean matchesSafely(<List_Item_class> listItem) {
            m_message = "Expected " + listItem+ " and got ";
            if (listItem== null) {
                m_message +=  "empty";
                return false;
            }
            return <assertion to check `check_value` is corresponding to `listItem` or not>;
        }
    };
}

Taken from: accessing children in custom expandablelist using android espresso

Hope it will help