Issue
I'm using espresso to add tests to my Android application.
In my TestActivity, I have some views that are only visible when the user is signed. The userIsSignedIn flag is stored in MyApp which is a subclass of android.app.Application. Is there a way I can access an instance of MyApp within the test case?
If not, what is alternative way to do this?
Thanks
Solution
In your test class you can use something like this:
@Rule
public ActivityTestRule<MainActivity> mActivityRule =
new ActivityTestRule<>(MainActivity.class);
Then in your test method:
@Test
public void doSomething() {
//....
mActivityRule.getActivity().getApplication();
}
Answered By - Gabriele Mariotti
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.