Unit Testing and Android DownloadManager -
i unit test class makes use of android downloadmanager service, i'm not sure how go doing it. should use downloadmanager service or there way can mock up? rather not have test call external web server. there existing testing library can use this?
- this solution use robolectric
one important thing know the count of download manager requests starts @ -1. if enqueue request, request count gonna 0.
- mock downloadmanager object
write test
public void shouldenqueuerequest() { //... //... verify(downloadmanager, times(1)).enqueue(anyobject()); //is downloadmanager empty assertthat(shadowof(downloadmanager).getrequestcount(), greaterthan(-1)); //get request downloadmanager shadowrequest realrequest = shadowof(shadowof(downloadmanager).getrequest(0)); assertthat(realrequest, notnullvalue()); assertthat(realrequest.getdescription(), equalto("your description")); assertthat(realrequest.gettitle(), equalto(app_name)); }
Comments
Post a Comment