udacity / AdvancedAndroid_TeaTime

115 stars 307 forks source link

TESP.04-Solution-AddIdlingResourceMenuActivityTest #26

Open HasanElHefnawy opened 4 years ago

HasanElHefnawy commented 4 years ago

In TESP.04-Solution-AddIdlingResourceMenuActivityTest, MenuActivityScreenTest doesn't pass any more!!! Also, in MenuActivity, there is a comment saying "We call ImageDownloader.downloadImage from onStart or onResume instead of in onCreate to ensure there is enougth time to register IdlingResource if the download is done too early (i.e. in onCreate)". This comment makes a feeling that mIdlingResource should be assigned and registered @Before registerIdlingResource() before calling ImageDownloader.downloadImage() in onStart(). And in this case (similar to IdlingResourceSample), there would be no need to call getIdlingResource() in onCreate(). However, when using Logs, it is clear that all of onCreate(), onStart(), and onResume() in MenuActivity are actually called before @Before registerIdlingResource() in IdlingResourceMenuActivityTest. That's why we must call getIdlingResource() in onCreate() to initialize mIdlingResource before using it in ImageDownloader.downloadImage().