You need to sign in to do that
Don't have an account?
Abhiram Sheshadri 9
Getting Error while saving the following test class while doing APEX REST Callouts Trailhead module
Class : Standard stuff from salesforce
@isTest
private class AnimalsCalloutsTest {
@isTest static void testGetCallout() {
// Create the mock response based on a static resource
StaticResourceCalloutMock mock = new StaticResourceCalloutMock();
mock.setStaticResource('GetAnimalResource');
mock.setStatusCode(200);
mock.setHeader('Content-Type', 'application/json;charset=UTF-8');
// Associate the callout with a mock response
Test.setMock(HttpCalloutMock.class, mock);
// Call method to test
HttpResponse result = AnimalsCallouts.makeGetCallout();
// Verify mock response is not null
System.assertNotEquals(null,result,
'The callout returned a null response.');
// Verify status code
System.assertEquals(200,result.getStatusCode(),
'The status code is not 200.');
// Verify content type
System.assertEquals('application/json;charset=UTF-8',
result.getHeader('Content-Type'),
'The content type value is not expected.');
// Verify the array contains 3 items
Map<String, Object> results = (Map<String, Object>)
JSON.deserializeUntyped(result.getBody());
List<Object> animals = (List<Object>) results.get('animals');
System.assertEquals(3, animals.size(),
'The array should only contain 3 items.');
}
}
While saving getting
Error: Compile Error: Method does not exist or incorrect signature: [StaticResourceCalloutMock].setStaticResource(String) at line 7 column 9
@isTest
private class AnimalsCalloutsTest {
@isTest static void testGetCallout() {
// Create the mock response based on a static resource
StaticResourceCalloutMock mock = new StaticResourceCalloutMock();
mock.setStaticResource('GetAnimalResource');
mock.setStatusCode(200);
mock.setHeader('Content-Type', 'application/json;charset=UTF-8');
// Associate the callout with a mock response
Test.setMock(HttpCalloutMock.class, mock);
// Call method to test
HttpResponse result = AnimalsCallouts.makeGetCallout();
// Verify mock response is not null
System.assertNotEquals(null,result,
'The callout returned a null response.');
// Verify status code
System.assertEquals(200,result.getStatusCode(),
'The status code is not 200.');
// Verify content type
System.assertEquals('application/json;charset=UTF-8',
result.getHeader('Content-Type'),
'The content type value is not expected.');
// Verify the array contains 3 items
Map<String, Object> results = (Map<String, Object>)
JSON.deserializeUntyped(result.getBody());
List<Object> animals = (List<Object>) results.get('animals');
System.assertEquals(3, animals.size(),
'The array should only contain 3 items.');
}
}
While saving getting
Error: Compile Error: Method does not exist or incorrect signature: [StaticResourceCalloutMock].setStaticResource(String) at line 7 column 9
Please check any class is exist in your org having same name of StaticResourceCalloutMock.
if it is there please remove or rename it.
All Answers
Check once Static Resource Name in Your Org .compare both names are same are not in the line mock.setStaticResource('GetAnimalResource');
I checked the Static Resource name in the org, it's exactly same as the one I have passed as a string to the setStaticResource() method. Don't know what the issue is.
Thanks,
Abhiram
Please check any class is exist in your org having same name of StaticResourceCalloutMock.
if it is there please remove or rename it.
Found a class by mistake I had created with the same name. That solves and have passed the challenge.