Issue
I have espresso test for Android:
@Test
public void ExternalBankAccountDetailsFragment_InfoShown() throws InterruptedException {
// SETUP
mockRequest();
clickOnItem();
mActivityRule.getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
Thread.sleep(100);
// CHECKS
onView(withId(R.id.view)).check(matches(hasDescendant(withText("test"))));
}
And I need to use Thread.sleep to wait the async call. But I know that this is not a good practice. I'm familiar with IdlingResources, but I can not use it because I have to change my code to use it (for ex. CountingIdlingResource usage inside callback etc).
How can I avoid usage of Thread.sleep()?
Solution
In the end all solutions will do something like Thread.sleep. The question is: How can you only wait for the minimum required amount of time?
One alternative to Idling Resources is this tiny ConditionWatcher library:https://github.com/AzimoLabs/ConditionWatcher
You can create an Instruction that waits checks if the current activity can find a view example
Answered By - Kaskasi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.