I'm getting the following error when I run a JUnit test on an android app that uses apachehttp-client. The app runs successfully on my test device and on an emulator. A login JUnit test also passes but the rest of the JUnit tests fail whenever the app tries to use the apachehttp-client to read data from a server.
The test seems to fail at httpClient.execute
try {
URL businessPartnersResource = new URL(
session.getServer().getUrl(), "BusinessPartners");
HttpGet request = new HttpGet(businessPartnersResource.toURI());
session.attachToRequest(request);
HttpClient httpClient = HttpClientFactory.getClient();
HttpResponse response = httpClient.execute(request);
int status = response.getStatusLine().getStatusCode();
switch (status) {
case HttpsURLConnection.HTTP_OK: {
Here's the Failure Trace
java.lang.UnsatisfiedLinkError: android.util.Log.isLoggable(Ljava/lang/String;I)Z
at android.util.Log.isLoggable(Native Method)
at org.apache.http.client.protocol.RequestClientConnControl.process(RequestClientConnControl.java:76)
at org.apache.http.protocol.BasicHttpProcessor.process(BasicHttpProcessor.java:251)
at org.apache.http.protocol.HttpRequestExecutor.preProcess(HttpRequestExecutor.java:168)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:458)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:641)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:576)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:554)
Frustrating, but you'll have to use a RobolectricTestRunner instead of the standard JUnit one.
isLoggable is a native method so its not available at runtime.
If you use Volley or the apachehttp-client, the biggest issue is that isLoggable is called as a field instantiation, for example:
private static final DEBUG = Log.isLoggable(..);
Which completely messes things up given that this method is simply not available at all within those libraries at runtime, so even an AndroidTestCase
can't save you.
Luckily, Robolectric handles it perfectly.
Edit April 4, 2017
JUnit 5 is available now and I have not tested with this testrunner.
I had the same issue, try extending AndroidTestCase in your test class. The error is due to classes that can be found only on the android runtime (Device\Emulator)
For me, it happened when running a specific test on kotest
. I had to run all the tests at once instead of one by one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With