+ Start a Discussion
mani toolmani tool 

Methods defined as TestMethod do not support Web service callouts : code covergae error

im creating custom object and fields using metadata api, and im getting below error:


Methods defined as TestMethod do not support Web service callouts.

how to solve this
Raj VakatiRaj Vakati
You need to do it two steps 

First in your class set
if(!Test.isRunnningTest()){
... YOUR HTTP CODE
}

then set mock response in your test class by using 
Test.setMock(HttpCalloutMock.class, mock);

StaticResourceCalloutMock mock = new StaticResourceCalloutMock();
mock.setStaticResource('NameOfStaticResourceContainingResponseBodyString');
mock.setStatusCode(200); // Or other appropriate HTTP status code
mock.setHeader('Content-Type', 'application/json'); // Or other appropriate MIME type like application/xml
Test.setMock(HttpCalloutMock.class, mock);