Feedback on ViewSelector unit testing API

6 views
Skip to first unread message

Nik Haldimann

unread,
May 17, 2013, 10:51:18 AM5/17/13
to robol...@googlegroups.com
Hi!

I've been working on ViewSelector, a library to make unit testing Android UIs easier with CSS-style selectors (partly inspired by Android's own UiSelector). It works with Android tests as well as with Robolectric (yes, also with the brand new 2.0). I've been using it successfully in my own projects but I'd like to get some feedback about the API from others before I put out a final release.

An example to give you a general idea:

    // These traditional assertions ...
    ListView view = (ListView) activity.findViewById(R.id.groceries);
    assertEquals(2, view.getChildCount());
    assertEquals("milk", ((TextView) view.getChildAt(0)).getText());
    assertEquals("cereal", ((TextView) view.getChildAt(1)).getText());

    // ... can be expressed with ViewSelector as:
    assertThat(selection("ListView#groceries TextView", activity))
        .hasSize(2)
        .hasAttributesEqualTo("text", "milk", "cereal");

More examples on the GitHub page at https://github.com/nikhaldi/android-view-selector

Does the API seem intuitive to you? Any other assertions that would be useful to you? There's an alpha release on Maven Central if you want to try it out.

Nik
Reply all
Reply to author
Forward
0 new messages