You need to sign in to do that
Don't have an account?
Veena Gopal
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.
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.
This was because in my Org I had a class called Test. When I removed that class, the issue was solved.
All Answers
It is a example from the trailhead. it is there in the trailhead itself.
@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.');
}
}
This was because in my Org I had a class called Test. When I removed that class, the issue was solved.