Android UI Testing Basics

I am currently looking for the core Android UI Testing Framework and Android Studio.

The docs on the Android developer site are for Eclipse, but I am using Android Studio. I was looking at Robolectric, the previously mentioned default framework, WebDriver thing, etc., but all seem outdated or too complex.

I have an almost complete project, so I cannot start from some Github project. I have tried combining Deckard , wiliamsouza bluetooth project ( see ), etc., without any success.

What's the currently preferred Android UI testing framework? Can you show me a step by step guide for it in Android Studio? I've been looking for it for several days now.

Thank!

+3


source to share


1 answer


Have you tried Robotium first ? It's lightweight and works for both native and hybrid apps. I use it a lot. Integrates seamlessly with Maven, Gradle or Ant to run tests as part of continuous integration.

import junit.framework.Assert;

public class EditorTest extends ActivityInstrumentationTestCase2<EditorActivity> {
    private Solo solo;

    public EditorTest() {
        super(EditorActivity.class);
    }

    public void setUp() throws Exception {
        solo = new Solo(getInstrumentation(), getActivity());
    }

    public void testPreferenceIsSaved() throws Exception {
        solo.sendKey(Solo.MENU);
        solo.clickOnText("More");
        solo.clickOnText("Preferences");
        solo.clickOnText("Edit File Extensions");
        Assert.assertTrue(solo.searchText("rtf"));

        solo.clickOnText("txt");
        solo.clearEditText(2);
        solo.enterText(2, "robotium");
        solo.clickOnButton("Save");
        solo.goBack();
        solo.clickOnText("Edit File Extensions");
        Assert.assertTrue(solo.searchText("application/robotium"));
    }

    @Override
    public void tearDown() throws Exception {
        solo.finishOpenedActivities();
    }
}

      



Secondly, Espresso . Another easily integrates with Gradle. Official Google IO video

onView(withId(R.id.my_view))      // withId(R.id.my_view) is a ViewMatcher
        .perform(click())               // click() is a ViewAction
        .check(matches(isDisplayed())); // matches(isDisplayed()) is a ViewAssertion

      

+4


source







All Articles