Android testing with Robotium (click on Button)

Robotium is the framework what allow us to create automatic tests for Android.

Let’s see small example how to click on ImageButton (or other) using its id.

public void testAboutBtn() {
      // get a list of all ImageButtons on the current activity
      List btnList = solo.getCurrentImageButtons();
      for (int i = 0; i < btnList.size(); i++) {
            ImageButton btn = btnList.get(i);
            // find button by id
            if (btn.getId() == {
                  // click on the button using index (not id !!!)
                  // check if new activity is the ‘About’
                  assertEquals(About.class, solo.getCurrentActivity().getClass());
            } else {
                  // other code