Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JUnit UnsatifiedLinkError:android.util.Log.isLoggable(Ljava/lang/String;_Java_Android_Junit_Apache Httpclient 4.x - Fatal编程技术网

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

JUnit UnsatifiedLinkError:android.util.Log.isLoggable(Ljava/lang/String;,java,android,junit,apache-httpclient-4.x,Java,Android,Junit,Apache Httpclient 4.x,在使用apachehttp客户端的android应用程序上运行JUnit测试时,我遇到以下错误。该应用程序在我的测试设备和模拟器上成功运行。登录JUnit测试也通过,但当应用程序尝试使用apachehttp客户端从服务器读取数据时,其余JUnit测试失败 httpClient.execute上的测试似乎失败 try { URL businessPartnersResource = new URL( session.getServer().getUr

在使用apachehttp客户端的android应用程序上运行JUnit测试时,我遇到以下错误。该应用程序在我的测试设备和模拟器上成功运行。登录JUnit测试也通过,但当应用程序尝试使用apachehttp客户端从服务器读取数据时,其余JUnit测试失败

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: {
这是失败的痕迹

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)

在Android项目上运行JUnit测试

在android中运行junit测试的唯一区别是,您将调用RunAs>android junit测试,而不是像在java中那样只调用junit测试


仅此而已!希望您喜欢它!

我也有同样的问题,请尝试在测试类中扩展AndroidTestCase。错误是由于只能在android运行时(设备\模拟器)上找到的类造成的。

令人沮丧,但您必须使用一个而不是标准的JUnit

isLoggable是本机方法,因此在运行时不可用

如果使用Volley或apachehttp客户端,最大的问题是isLoggable被称为字段实例化,例如:

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

这完全把事情搞砸了,因为这种方法在运行时根本不在这些库中可用,所以即使是
AndroidTestCase
也无法保存您

幸运的是,Robolectric处理得很好

编辑2017年4月4日

JUnit5现在可用,我还没有使用这个testrunner进行测试