0

I'm trying to do is to test these with unit tests.

My app is filled with API calls that look like this

    public void getCategoryFeed(CategoryFeedDataFactoryCallback callback) {
    String url = Constants.BASE_URL + "api/v1/forums/categories";
    final CategoryFeedDataFactoryCallback listReceivedCallback = callback;

    GsonRequest<CategoryResponse> request = new GsonRequest<>(url, CategoryResponse.class
            , null, Request.Method.GET, null, new Response.Listener<CategoryResponse>() {
        @Override
        public void onResponse(CategoryResponse response) {
            listReceivedCallback.onCategoryDataReceived(response);
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            listReceivedCallback.onCategoryDataFailed(error);
        }
    });

    RequestFactory.getInstance(mContext).addtoRequestQueue(request);

    request.setRetryPolicy(new DefaultRetryPolicy(
            10000,
            DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT
    ));

}
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
BilalMH
  • 175
  • 1
  • 21
  • Related - http://stackoverflow.com/questions/9440663/unit-testing-rest-api#9440741 – OneCricketeer Jan 25 '17 at 20:27
  • @cricket_007 I really don't understand that. Any chance of elaborating? I'm new to unit tests so have no idea what I'm doing – BilalMH Jan 25 '17 at 20:30
  • Basically, integration tests are separate from *unit* tests. IMO, unit tests are more for your own code's functions, whereas integrations tests are for testing like an API can communicate with your functions correctly. In other words, the API "unit testing" should be done server-side. – OneCricketeer Jan 25 '17 at 20:47
  • @cricket_007 so look at doing integration testing? – BilalMH Jan 25 '17 at 20:51
  • I think so... Though, I don't know if there's like a "library" for it. It's more just a pattern of writing the code. If you're going for "code coverage", that's a separate topic. Additionally, you can create what are called "mock" API calls that just return pre-defined data to your app. And that is what you unit test – OneCricketeer Jan 25 '17 at 22:26

0 Answers0