Issue
I have an app where either one activity (let's call it ActivityA
) or another (ActivityB
) can lead to the same target activity (ActivityC
).
In my code, ActivityC
has a button that leads back to the previous activity: either ActivityA
or ActivityB
, depending on which one has called ActivityC
.
I'd like to write some unit tests with Espresso to validate this flow but don't know how to figure out which activity has called ActivityC
. The code below illustrates my problem:
String extra = getIntent().getStringExtra("key"); // How can I store the extra value?
if (ActivityA.class.getName().equals(extra)) {
intended(hasComponent(ActivityA.class.getName()));
} else if (ActivityB.class.getName().equals(extra)) {
intended(hasComponent(ActivityB.class.getName()));
}
Having this accomplished, my test will be able to validate whether the intent is pointing towards the correct target activity.
Solution
I eventually figured out that Espresso doesn't have methods that can do what I was trying to, given the fact that the responsibility of validating whether ActivityC
was leading back to its previous activity lies within the unit tests for both ActivityA
and ActivityB
.
Basically what has been done to solve the issue was to make ActivityA
(or B) call ActivityC
and then have ActivityC
call its previous activity in its own way, regardless of which one it is.
Answered By - 92AlanC
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.