You need to sign in to do that
Don't have an account?
test vijay
Methods defined as TestMethod do not support Web service callouts + apex class
hi developers,
following is my test class.
Thanks in advance
@future (callout=true) Public static void sendHTTPRequest(String url, String body){ Http http = new Http(); HttpResponse res = new HttpResponse(); HttpRequest req = new HttpRequest(); req.setEndpoint(url); req.setBody(body); req.setMethod('POST'); try { res = http.send(req); } catch(System.CalloutException e) { System.debug('CalloutException: '+ e); System.debug(res.toString()); } }above is my future callout method. I am trying to cover this method but error is coming : Methods defined as TestMethod do not support Web service callouts.
following is my test class.
@isTest public class colloutTest { @isTest public static void testAccTriHandler(){ test.startTest(); string key = 'https://orgBaseUrl.salesforce.com/identity/connect/token'; string body = '{"name" : 'dummy'}'; AccountCustomerNumber.sendHTTPRequest(key, body); test.stopTest(); } }can somebody guide me that how to fix this problam.
Thanks in advance
You should implement HttpCalloutMock class when testing with Web servoce callouts in Apex.
Reference:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_callouts_wsdl2apex_testing.htm
Please modify your test class in following manner: Hope above information helps, Please mark as Best Answer so that it can help others in the future.
Thanks.
All Answers
You should implement HttpCalloutMock class when testing with Web servoce callouts in Apex.
Reference:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_callouts_wsdl2apex_testing.htm
Please modify your test class in following manner: Hope above information helps, Please mark as Best Answer so that it can help others in the future.
Thanks.
it's working.