while calling method
@isTest
public class call_Test{
static testMethod void unitTest(){
uptodel.qTis();
}
}
its given error that Methods defined as TestMethod do not support Web service callouts
public class uptodel {
public static final String ts_url = 'https://example.com/study';
public static void qTis() {
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint(ts_url);
request.setMethod('GET');
HttpResponse response = http.send(request);
if (response.getStatusCode() == 200) {
Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
List<Object> contacts = (List<Object>) results.get('contacts');
for (Object contact: contacts) {
System.debug(contact);
}
}
}
}
Best Answer
Since your test calls a method that executes a callout you need to mock the response during test methods.
The easiest way to do this is in sfdcfox's post here:
Help on Invokable Apex Test class and @Future callout Apex test Class
He was even kind enough to put an example test method in there