3

I'm looking for the currently mainstream Android UI Testing Framework & Android Studio.

The docs on the Android Developer site are for Eclipse, but I using Android Studio. I've looked Robolectric, the previously said default framework, the WebDriver thing, etc., but all look deprecated, or too complicated.

I have an almost complete project, so I cannot start from some based Github project. I tried to merge Deckard, wiliamsouza's bluetooth project (see), and so on, without any success.

What are the currently preferred UI Testing Framework for Android? Can you show me a step-by-step tutorial for it with Android Studio? I've been looking for it for days now.

Thanks!

Nagy Vilmos
  • 1,878
  • 22
  • 46
  • I recommend you to try this library: https://github.com/mauriciotogneri/green-coffee You just need to import it and then you will be able to run your tests written in Gherkin. – Mauricio Togneri Feb 04 '17 at 10:06

1 Answers1

4

First, did you try Robotium? It's easy and works for both native, hybrid apps. I use it very often. Integrates smoothly 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();
    }
}

Second, Espresso. Another easy to integrate 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
Cory Petosky
  • 12,458
  • 3
  • 39
  • 44
Taranfx
  • 10,361
  • 17
  • 77
  • 95
  • Ok, I tried, and it looks good. But how can I use assertEqual on an `EditText`'s value? I'm trying `Assert.assertEquals(solo.getEditText(..id..).toString(), "Text");`, but it do not works. Also tried http://stackoverflow.com/a/22969743/2891426 – Nagy Vilmos Oct 03 '14 at 16:59
  • Appium seems to promising and easy. http://appium.io/ – Hamedz Jun 13 '16 at 16:51