Saturday, January 26, 2019

Volley and Robolectric

Yesterday I set up unit testing for an Android project using the Robolectric test framework. The app depends on Volley, which works fine in Android. But trying to run the unit test in the JVM produced a crash stating that the org.apache.http.client.HttpClient class could not be found. I tried adding empty classes with the appropriate names to sidestep that error and similar subsequent ones, but couldn't get the test to start. Eventually I found that Robolectric provides a shadow implementation of the necessary classes, but it's in another dependency. Adding that to the Gradle project file fixed the problem:

testImplementation 'org.robolectric:shadows-httpclient:4.1'

No comments:

Post a Comment