udacity / AdvancedAndroid_TeaTime

115 stars 307 forks source link

TESP.02-Solution-AddMenuActivityScreenTest error #2

Closed S2606 closed 7 years ago

S2606 commented 7 years ago

on running the test on an emulator, a error android.support.test.espresso.PerformException: Error performing 'load adapter data' on view 'with id: com.example.android.teatime:id/tea_grid_view'. occurs.

luishts commented 7 years ago

Try registering an IdlingResource like file IdlingResourceMenuActivityTest.

private IdlingResource mIdlingResource;

// Registers any resource that needs to be synchronized with Espresso before the test is run. @Before public void registerIdlingResource() { mIdlingResource = mActivityTestRule.getActivity().getIdlingResource(); // To prove that the test fails, omit this call: Espresso.registerIdlingResources(mIdlingResource); }

@After public void unregisterIdlingResource() { if (mIdlingResource != null) { Espresso.unregisterIdlingResources(mIdlingResource); } }

I think this error happens because MenuActivity.java simulates a large file download at onStart() registering a mIdlingResource so if you try to run a test without using an IdlingResource the test will fail.

S2606 commented 7 years ago

Thanks @luishts for helping me

luishts commented 7 years ago

@S2606, your welcome! I had the same problem and I'm glad that it helped.