I was trying to test an apex class that uses some http callouts with HTTPMockRequest. When trying to run the Test class it gives me the following error:
Methods defined as TestMethod do not support Web service callouts
This is my Test class
@isTest()
public class retrieveGAdata_Test {
public static final string sDate = 'yesterday';
public static final string eDate = 'today';
public static testmethod void testsaveDataToSF()
{
retrieveGaData test1 = new retrieveGAdata();
SingleRequestMock fakeAccountResp = new SingleRequestMock(200,
'Complete',
'[{"Name": "sForceTest1"}]',
null);
SingleRequestMock fakeContactsResp = new SingleRequestMock(200,
'Complete',
'[{"LastName": "Test Last Name"}]',
null);
Map<String, HttpCalloutMock> endpoint2TestResp =
new Map<String,HttpCalloutMock>();
endpoint2TestResp.put('https://accounts.google.com/o/oauth2/token',fakeAccountResp);
endpoint2TestResp.put('https://www.googleapis.com/analytics/v3/data/',fakeContactsResp);
HttpCalloutMock multiCalloutMock =
new MultiRequestMock(endpoint2TestResp);
Test.setMock(HttpCalloutMock.class, multiCalloutMock);
}
}