I’m trying to test HTTP calls using the Robolectric test framework’s HTTP layer.
My test class is already annotated with RunWith(RobolectricTestRunner.class). Here’s a sample HTTP test case:
@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"));
}
This test fails and the JUnit Failure Trace reports the following DefaultRequestDirector exception (originating from the sendRequest() call):
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)
Any ideas what might be causing the Apache class to throw an exception?
Using the current latest library, robolectric-1.2-20120730.165026-113-jar-with-dependencies.jar.
Found the answer on the Robolectric Google Group: https://groups.google.com/forum/#!msg/robolectric/jWwWjQ23wHI/X9b_ZdDMJg0J
cached-robolectric-classes.jar. If you followed Robolectric’s installation instructions for Eclipse, this file will be under [your main Android project]/tmp.