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?

  1. this solution use robolectric

one important thing know the count of download manager requests starts @ -1. if enqueue request, request count gonna 0.

  1. mock downloadmanager object
  2. 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

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -