Test.setMock() is not working

Error: Method does not exist or incorrect signature: void setMock(System.Type, System.StaticResourceCalloutMock) from the type test

enter image description here

Source Code:

private class AnimalsCalloutsTest {
    @isTest static  void testGetCallout() {
        // Create the mock response based on a static resource
        StaticResourceCalloutMock mock = new StaticResourceCalloutMock();
        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   
          'The content type value is not expected.');  
        // Verify the array contains 3 items     
        Map<String, Object> results = (Map<String, Object>) 
        List<Object> animals = (List<Object>) results.get('animals');
        System.assertEquals(3, animals.size(), 'The array should only contain 3 items.');          

1 Answer 1


Any time you see this sort of error where a standard class appears to be missing methods, it is almost always caused by name shadowing. Double check that you do not have any variables nor classes named Test. If this issue is what blocks you currently, you should try to resolve the name shadowing first. Failing that, the workaround would be to instead reference System.Test instead of Test, which will disambiguate.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .