gpt4 book ai didi

android - Robolectric HTTP 测试在 NoSuchMethodError : org. apache.http.impl.client.DefaultRequestDirector 上失败

转载 作者:搜寻专家 更新时间:2023-11-01 07:35:31 25 4
gpt4 key购买 nike

我正在尝试使用 Robolectric 测试框架的 HTTP layer 测试 HTTP 调用.

我的测试类已经用 RunWith(RobolectricTestRunner.class) 注释了。这是一个示例 HTTP 测试用例:

@Test
public void testHttpGet() {
Robolectric.addPendingHttpResponse(200, "All your requests are belong to Robolectric");
String response = ConnectionUtils.sendRequest();
assertThat(response, equalTo("All your requests are belong to Robolectric"));
}

此测试失败并且 JUnit 失败跟踪报告以下 DefaultRequestDirector 异常(源自 sendRequest() 调用):

java.lang.NoSuchMethodError: org.apache.http.impl.client.DefaultRequestDirector.<init>(Lorg/apache/commons/logging/Log;Lorg/apache/http/protocol/HttpRequestExecutor;Lorg/apache/http/conn/ClientConnectionManager;Lorg/apache/http/ConnectionReuseStrategy;Lorg/apache/http/conn/ConnectionKeepAliveStrategy;Lorg/apache/http/conn/routing/HttpRoutePlanner;Lorg/apache/http/protocol/HttpProcessor;Lorg/apache/http/client/HttpRequestRetryHandler;Lorg/apache/http/client/RedirectHandler;Lorg/apache/http/client/AuthenticationHandler;Lorg/apache/http/client/AuthenticationHandler;Lorg/apache/http/client/UserTokenHandler;Lorg/apache/http/params/HttpParams;)V
at org.apache.http.impl.client.AbstractHttpClient.createClientRequestDirector(AbstractHttpClient.java:660)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:625)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:576)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:554)

任何可能导致 Apache 类抛出异常的想法?

使用当前最新的库,robolectric-1.2-20120730.165026-113-jar-with-dependencies.jar。

最佳答案

在 Robolectric Google Group 上找到了答案:https://groups.google.com/forum/#!msg/robolectric/jWwWjQ23wHI/X9b_ZdDMJg0J

  1. 右键单击 Robolectric Java 测试项目 > 属性 > Java 构建路径 > 订购和导出。
  2. 将 robolectric jar 移到库列表的顶部。
  3. 查找并删除 cached-robolectric-classes.jar。如果您按照 Robolectric 的 Eclipse 安装说明进行操作,则此文件将位于 [您的主要 Android 项目]/tmp 下。
  4. 重新运行 JUnit 并继续工作。

关于android - Robolectric HTTP 测试在 NoSuchMethodError : org. apache.http.impl.client.DefaultRequestDirector 上失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11800138/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com