JUnit UnsatisfiedLinkError: android.util.Log.isLoggable (Ljava / lang / String;

I get the following error when running the JUnit test in an Android application using apachehttp-client. The application runs successfully on my test device and on the emulator. The JUnit test also passes, but the rest of the JUnit tests do not work when the application tries to use apachehttp-client to read data from the server.

The test seems to fail in 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 failure tracking

 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) 
+6
source share
3 answers

Disappointing, but you will have to use RobolectricTestRunner instead of the standard JUnit.

isLoggable is a native method, so it is not available at run time.

If you are using Volley or apachehttp-client, the biggest problem is that isLoggable is called as instantiating a field, for example:

private static final DEBUG = Log.isLoggable(..);

Which is completely useless, given that this method is simply not available at all in these libraries at runtime, so even AndroidTestCase cannot save you.

Fortunately, Robolectric does a great job of this.

Edit April 4, 2017

JUnit 5 is now available, and I have not tested it with this tester.

+6
source

I had the same problem, try extending AndroidTestCase in your test class. The error is related to classes that can only be found in the android runtime (Device \ Emulator)

+1
source

Running JUnit tests on Android projects.

The only difference when running the junit test in android is that you will call Run As> Android JUnit Test instead of JUnit Test, as you are used to in java.

That's all! I hope you will like it!

-3
source

Source: https://habr.com/ru/post/983710/


All Articles