Lena Bru
Lena Bru

Reputation: 13947

Testing activity flow with robotium

I want to test some flow using robotium

my flow has to go through several activities, and do some assertions in the middle

my problem is, that once the activity changes, the test ends successfully

how do i test going through several activities in 1 test?

i am using robotium 5.0.1

Upvotes: 1

Views: 936

Answers (2)

Saurabh
Saurabh

Reputation: 995

Its quite simple to achieve. You can fire event and check result using assert API inside one method

public void testAllActivity(){
    Solo solo = new Solo(getInstrumentation(), getActivity());

    // View1 is a view that is lying in Activity1
    solo.clickOnButton(view1);

    // Put a delay so that you testing with assert doesn't fail.
    solo.waitForActivity("Activity2");
    solo.assertCurrentActivity("<Error Message>","Activity2.class");
    // View2 is a view that is lying in Activity2
    solo.clickOnButton(view1);
    // Put a delay so that you testing with assert doesn't fail.
    solo.waitForActivity("Activity3");
    solo.assertCurrentActivity("<Error Message>","Activity3.class");
}

Thats it and you are done in one go.

Upvotes: 1

Isaac Zais
Isaac Zais

Reputation: 583

Robotium should be able to handle switching activities just fine.

Are you are using Solo to click on the buttons (or images etc...) i.e.

Solo solo = new Solo(getInstrumentation(), getActivity());
//button is a button in activity1 that launches activity2
solo.clickOnButton(button);
//Now we are in Activity2

//otherButton is a button in activity2 that launches activity3
solo.clickOnButton(otherButton);
//Now we are in Activity3

//Check the Current Activity
solo.assertCurrentActivity("Error Message", Activity3.class);

Posting some code might get you a more personalized response

This might also help: https://groups.google.com/forum/#!topic/robotium-developers/lcneCX_nYPQ

Upvotes: 0

Related Questions