I am testing an anroid app using Mockito
. I want to test an exception case, but the method Mockito.doThrow
hangs and the test never gets executed (it neither fails nor succeeds).
Here's the code. PackageDownloader
represents an AsyncTask
. Its method get
gets called inside of the downloadPackage
method. But the execution never comes to that point because it hangs exactly on doThrow
line.
PackageDownloader packageDownloader = new PackageDownloader();
PackageDownloader mockPackageDownloader = Mockito.spy(packageDownloader);
HttpURLConnection connectionMock = Mockito.mock(HttpURLConnection.class);
Mockito.doReturn(connectionMock)
.when(mockPackageDownloader)
.createConnection(Mockito.any(URL.class));
Mockito.doThrow(new InterruptedException()).when(mockPackageDownloader).get();
downloadPackage();
Aucun commentaire:
Enregistrer un commentaire