title: how to unit test http request android
body: <p>I have used library <code>Robolectric</code> another possible framework. Http client for Android <a href="http://loopj.com/android-async-http/" rel="noreferrer">http://loopj.com/android-async-http/</a></p>
  
  <pre><code>static AsyncHttpClient client = new AsyncHttpClient();
  
  public static void getData (final ServerCallback callback) {
  
      client.get("http://httpbin.org/get", new AsyncHttpResponseHandler() {
  
          @Override
          public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
              callback.onSuccess(statusCode, new String(responseBody));
          }
  
          @Override
          public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
              callback.onFailure(statusCode, new String(responseBody));
          }
  
      });
  }
  </code></pre>
  
  <p>Test Class:</p>
  
  <pre><code>@RunWith(RobolectricTestRunner.class)
  public class ApiTest{
  
  @Test
  public void testgetData () {
  
  }
  
  }
  </code></pre>
  
  <p>interface</p>
  
  <pre><code>public interface ServerCallback {
      // Api detect connection
      void onSuccess(int statusCode, String response);
      void onFailure(int statusCode, String response);
  }
  </code></pre>