You need to sign in to do that
Don't have an account?
anu35
Http response code coverage.
Hi All,
how can i cover http resonce in code coverage am facing this Error while running the Test class "Methods defined as TestMethod do not support Web service callouts"
Http htp = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint(ENDPOINT);
req.setMethod('GET');
HttpResponse res = new HttpResponse();
res = htp.send(req);
Thanks.
how can i cover http resonce in code coverage am facing this Error while running the Test class "Methods defined as TestMethod do not support Web service callouts"
Http htp = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint(ENDPOINT);
req.setMethod('GET');
HttpResponse res = new HttpResponse();
res = htp.send(req);
Thanks.
You need to make use of HttpCalloutMock interface to solve this issue. You can find out the implementation details here : https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_http_testing_httpcalloutmock.htm
Http htp = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint(ENDPOINT);
req.setMethod('GET');
HttpResponse res = new HttpResponse();
if(test.isRunningTest()){
res = htp.send(req);
}else{
res = ''; //Dummy Response
}
if answer help you then mark it best answer.