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
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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With