pivotal/robolectric — pull request #298 by jpkrohling (2012-08-03 14:28:59+00:00)
Title: Add support for logging external http calls

While testing an internal component, we came across a situation that was blocking our tests. The scenario involves an APKLIB, which is consumed by a real Android project. This APKLIB provides some services, that in turn calls some specific HTTP end points. In our case, we wanted to make sure that, given a certain API calls to the public interface of the APKLIB, an exact number of HTTP calls would be made to the server, no matter the implementation behind it. Besides that, the responses from the actual HTTP service are also under testing, so, it's basically an "end-to-end" test for our APKLIB from the perspective of a consumer of said API.

As such, we couldn't find a way to get Robolectric to work on this scenario. We either mocked the HTTP responses, or we just lose the ability to track the http calls made by the app by setting "interceptHttpRequests" to false.

This set of commits adds the possibility for a tester to make sure that real HTTP requests were made and that the server provided the expected response. This is probably an extreme use case, specially because Robolectric is mostly an unit-test framework, but we think this might be helpful for others.