1

I create a test call API with Robolectric with this code

    FakeHttp fakeHttpLayer = FakeHttp.getFakeHttpLayer();
    // Allow all Fake Http Request
    fakeHttpLayer.interceptHttpRequests(false);
    FakeHttp.setDefaultHttpResponse(200, "OK");

    // Setup the fake HTTP layer to return HTTP responses based on GET_DATA_URL
    ProtocolVersion httpProtocolVersion = new ProtocolVersion("HTTP", 1, 1);
    HttpResponse successResponse =
            new BasicHttpResponse(httpProtocolVersion, 200, "OK");

    // New HackerNewsAPI
    HackerNewsAPI hnAPI = HackerNewsAPI.getInstance(activity);

    // Check API not null
    Assert.assertNotNull(hnAPI);
    // Call request to GET_DATA_URL
    List<HNStory>  listDeleteStoryId = new ArrayList<HNStory>();
    hnAPI.GetTopStoryIds(NUMIDS, listDeleteStoryId);

    fakeHttpLayer.addHttpResponseRule(GET_DATA_URL, successResponse);
    // Check url GET_DATA_URL was made
    Assert.assertTrue(FakeHttp.httpRequestWasMade(GET_DATA_URL));

The Asset.assertTrue is error. It's false, mean that the request doesn't be made. Do I miss anything setting with Robolectric. Is there anyone can help me to solve it, why the request doesn't make. Thanks a lot !

Khang Tran
  • 467
  • 5
  • 16
  • Are you using apache http client? If I'm correct then `FakeHttp` is only working with mocking the apache http library. If you use okHttp than consider of usage okHttpMockWebServer – Eugen Martynov Dec 03 '15 at 07:22

0 Answers0