0

I've started learning Apex Integration Services trailhead. I'm unable to save a test class AnimalsCalloutsTest:

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

}

I'm getting error while I'm trying to save this test class, it's showing error:

name                    line    problem
animalscalloutstest     12      method does not exist or incorrect signature: Test.setMock(Type, StaticResourceCalloutMock)

I'm testing this for get method and with static resource. Why am I getting this error can anyone tell me?

2
  • 1
    Do you have a class named test in your org, if so that is an issue? What API Version is your class set at.
    – Eric
    Apr 24, 2016 at 4:28
  • @IlyaLepesh - I rolled back your title change as you cannot assume your answer is correct and change the title to reflect the OP's question is related to the context of your answer (even if I was correct and thus your detailed answer off of my comment proves to be true).
    – Eric
    Apr 24, 2016 at 15:04

1 Answer 1

3

I'm afraid that you have created class Test:

public class test {

}

SalesForce tries to use custom class, where method setMock doesn't exist. You should remove/rename it or specify system namespace before:

system.Test.setMock(HttpCalloutMock.class, mock);

You must log in to answer this question.

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