Android Espresso IdlingPolicies.setIdlingResourceTimeout not working

I have several classes for checking deep links. Each class 1 test has a deep link.

There are several tests that always end correctly in 10+ seconds when I run them individually, but always take more than 45 seconds to finish when I run them together.

enter image description here
Please note that all these tests should fail all the time (I have not completed their implementation), so the results should not change.

Am I using IdlingPolicies.setIdlingResourceTimeout incorrectly?

My test class:

 @RunWith(AndroidJUnit4.class) public class DeepLinkActivityBagTest extends MyActivityTest { @Rule public MyActivityTestRule<DeepLinkActivity> activityTestRule = new MyActivityTestRule<DeepLinkActivity>(DeepLinkActivity.class) { @Override protected Intent getActivityIntent() { Intent intent = super.getActivityIntent(); intent.setAction(Intent.ACTION_VIEW); intent.setData(Uri.parse("xxx://bag")); return intent; } }; @Test public void testCorrectScreenOpened() { setUpWait(); String expectedToolbarTitle = "shopping bag" + mToolbarTitleSuffix; onView(withTextIgnoreCase(expectedToolbarTitle)).check(matches(isDisplayed())); } } 

His parent class:

 @RunWith(AndroidJUnit4.class) public class MyActivityTest { @Rule public MyActivityTestRule<DeepLinkActivity> activityTestRule; protected String mToolbarTitleSuffix; @Before public void prepare() { if (!BuildConfig.FLAVOR.equals(ENV_PRODUCTION)) { mToolbarTitleSuffix = String.format(" (%s)", BuildConfig.FLAVOR); } } @After public void resetCountry() { if (activityTestRule != null) { PrefUtils.clear(InstrumentationRegistry.getTargetContext()); PrefUtils.setCurrentCountryCode(activityTestRule.getmCurCountryCode()); PrefUtils.setCurrentLangCode(activityTestRule.getmCurLangCode()); } } protected void setUpWait() { try { Thread.sleep(3 * 1000); } catch (InterruptedException e) { Logger.e(e, ""); } IdlingPolicies.setMasterPolicyTimeout(10, TimeUnit.SECONDS); IdlingPolicies.setIdlingResourceTimeout(5, TimeUnit.SECONDS); } } 

MyActivityTestRule:

 public class MyActivityTestRule<D extends Activity> extends ActivityTestRule { private String mCurCountryCode; private String mCurLangCode; protected MyActivityTestRule(Class activityClass) { super(activityClass); } public MyActivityTestRule(Class activityClass, boolean initialTouchMode) { super(activityClass, initialTouchMode); } public MyActivityTestRule(Class activityClass, boolean initialTouchMode, boolean launchActivity) { super(activityClass, initialTouchMode, launchActivity); } @Override protected void beforeActivityLaunched() { super.beforeActivityLaunched(); PrefUtils.setup(InstrumentationRegistry.getTargetContext()); mCurCountryCode = PrefUtils.getCurrentCountryCode(); mCurLangCode = PrefUtils.getCurrentLangCode(); PrefUtils.clear(InstrumentationRegistry.getTargetContext()); PrefUtils.setCurrentCountryCode("SG"); PrefUtils.setCurrentLangCode("en"); } String getmCurCountryCode() { return mCurCountryCode; } String getmCurLangCode() { return mCurLangCode; } } 
+5
source share

Source: https://habr.com/ru/post/1270769/


All Articles