0

I'm following the Apex Rest Callouts trail which instructs you to write a unit test for a sample class.

All code is given, you just need to add it into their ide.

The problem is, one line from the trail's code errors and I have no prior Apex knowledge, so I'm kind of lost.

The class in question is:

@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.');          
    }   
}

The error is in line 10 and says Method does not exist or incorrect signature: void setMock(System.Type, System.StaticResourceCalloutMock) from the type Test

The IDE is pretty rudimentary so it's difficult to see what type each expression has, but it seems the signature is incorrect (the method exists).

I'm not sure what it expects and following the trail further leads to the same error later on.

Moritz Roessler
  • 8,542
  • 26
  • 51

1 Answers1

0

I would check for some of these things:

Namespace Prefix, API Version, Dependency Issues.

de_classified
  • 1,927
  • 1
  • 15
  • 19