3

我使用espresso作爲我的UI自動化測試。我想爲ExpandableListView創建一個matcher,因爲它有時會出現在屏幕上,並且它不是很好的做法,因此在視圖上調用onView(withText("something"))時,該視圖會綁定adapter。有人可以告訴我如何爲ExpandableListView創建matcher使用ExpandableListView進行濃縮咖啡測試

+0

[訪問的孩子可能的複製在自定義可擴展列表使用android espresso](http://stackoverflow.com/questions/27220612/accessing-children-in-custom-expandablelist-using-android-espresso) – piotrek1543

回答

2

我不知道,如果這一個是有用的,但是:

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>; 
     } 
    }; 
} 

摘自:accessing children in custom expandablelist using android espresso

希望這將有助於