Is it possible to get an activity result from an instrumentation test?

472 Views Asked by At

I have an activity(A) in my app, which is started by an other activity(B) with startActivityForResult(). When a button is clicked in A, it will call setResult() and finish(), and go back to B.

How can I get that result from A, in my instrumentation tests?

I would like to keep it simple, and directly start A from my test, and not go trough B(and the activities before that).

I'm using robotium, and I've look into other tools too, and have not found anything useful.

getActivityMonitor().getResult() is null. Robotium does not start the activity with startActivityForResult() anyway. I don't want to mock the result from activity A, I want to check it's validity.

My current workaround is to read the value out of the activity with reflection, but there must be a better way.

1

There are 1 best solutions below

1
wpj On

if i understand your question correctly try this

Intent i = new Intent (getApplicationContext(), ActivityA.class); startActivity(i); //Start Activity A

or you can make the test star from specific activity

public class ActivityATest extends ActivityInstrumentationTestCase2<ActivityA> { ...

then in test check

// check that we have the right activity solo.assertCurrentActivity("wrong activity", ActivityA.class);