UnitTesting and functional testing on Android

I created an application that sends intents from several actions. After some research, I found that the class is ActivityUnitTestCaseintended for unit testing, and is ActivityInstrumentationTestCase2intended for functional testing. I understand the use of methods such as setUp(), tearDown()and testPreConditions(). However, I have a little difficulty trying to figure out which user tests will be created in the previous classes mentioned. I know that there are several methods that cannot be called in certain classes.

To be more specific, if I'm in activity A , and I press the button, then it is startActivityForResult()that triggers the activity of Bed and . Then I send the intent back to activity A , which is processed in the method onActivityResult(). How can I verify that the actual result is onActivityResult()equal to the expected result?

I searched a lot for any examples that would help eliminate this confusion. If anyone could provide any help, I would really appreciate it.

+3
source share
1 answer

, , , onActivityResult , , . ActivityInstrumentationTestCase2 Robotium ( ).

public class AdvancedSearchActivityTest extends ActivityInstrumentationTestCase2<AdvancedSearchActivity> {

    private Solo solo;

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        solo = new Solo(getInstrumentation(), getActivity());
    }

    public void testWhenActivityLoads_shouldShowCorrectWidgets() throws Exception {
        assertTrue(solo.searchText("Location:"));
        assertTrue(solo.searchText("Map Radius:"));
        assertTrue(solo.searchButton("Search"));
    }
}

ActivityInstrumentationTestCase2 , , ( ..), , . . , onActivityResult , .

+1

Source: https://habr.com/ru/post/1773996/


All Articles