function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Veena GopalVeena Gopal 

rest callout trailhead test class static resource get

rest callout trailhead test using static resource
I am getting the following error for a particular line. This is just a example given in the trailhead rest callouts testclass using static resource.
Line:Test.setMock(HttpCalloutMock.class, mock);
Error:Method does not exist or incorrect signature: void setMock(System.Type, System.StaticResourceCalloutMock) from the type test

As given in other posts, i have checked if there is a duplicate class named StaticResourceCalloutMock but i do not have any.
also the name of the static resource i have mentioned in the test class is correct.
Please help.
The code is as below:
@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); -----> this is the line which is giving error.
// 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.');
}
}

Only genuine ppl answer my question.
Best Answer chosen by Veena Gopal
Shruti SShruti S
I have posted my thoughts on your previous post, please have a look at that. Here is the link - https://developer.salesforce.com/forums?id=9060G000000Ub3XQAS

Let me know if that helps.