سؤال

Any framework in java to write simple rest tests for testing some restful calls.

I came across JerseyTest. But didn't find an example how to write a simple test

هل كانت مفيدة؟

المحلول

نصائح أخرى

You could test the Rest API using Apache HttpClient libraries. An example Java code would looks like below.

            String uri = "http://localhost:7001/myapis/search/json";
            URIBuilder uriBuilder = new URIBuilder(uri);
            uriBuilder.addParameter("institutionName", "HSBC%");
            uriBuilder.addParameter("isoCountryCode", "GB");

            HttpGet httpGet = new HttpGet(uriBuilder.build());
            HttpClient httpClient = new DefaultHttpClient();
            HttpResponse httpResponse = httpClient.execute(httpGet);
            HttpEntity httpEntity = httpResponse.getEntity();
            String result = EntityUtils.toString(httpEntity);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top