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
Charles Varner 11Charles Varner 11 

No Apex class named 'AnimalLocatorMock' was found

I'm getting an error "No Apex class named 'AnimalLocatorMock' was found" when validating the challenge.  However, everything seems to be coded correctly, and I have 100 percent code coverage on the AnimalLocator class.  I have no idea what's wrong with my test classes.  Does anyone have any ideas about what code be wrong?

@IsTest
private class AnimalLocatorTest {
    @isTest static  void  testGetCallout() {
    // Set mock callout class
    Test.setMock(HttpCalloutMock.class, new AnimalLocatorMock());
    // This causes a fake response to be sent
    // from the class that implements HttpCalloutMock.
    String animalname = AnimalLocator.getAnimalNameById(2);
    // Verify that the response received contains fake values        
    String expectedValue = 'bear';
    System.assertEquals(animalname, expectedValue);
    }
}

@IsTest
global class AnimalLocatorMock implements HttpCalloutMock {
    //Implement this interface method
    global HTTPResponse respond(HTTPRequest request) {
        // Create a fake response
        HttpResponse response = new HttpResponse();
        response.setHeader('Content-Type', 'application/json');
        response.setBody('{"animal":{"id":2,"name":"bear","eats":"berries, campers, adam seligman","says":"yum yum"}}');
        response.setStatusCode(200);
        return response;
    }
}
Best Answer chosen by Charles Varner 11
pconpcon
And, what about namespaced org?

All Answers

pconpcon
Just for clarification, they are in their own class files, right?  Is your org namespaced?
Charles Varner 11Charles Varner 11
Correct, the test class and mock class are in separate files. 
pconpcon
And, what about namespaced org?
This was selected as the best answer
Charles Varner 11Charles Varner 11
I'm not sure what you mean by namespaced org.  I've completed numerous trailheads, including the restful callout challenged in the same trailhead module.
Charles Varner 11Charles Varner 11
Thanks, I queried the apex class object via the dev console and saw that I wasn't getting any query results.  This happened even though I was viewing the file in DEV console and no asterick was showing next to the file name tab.  I deleted the file, pasted the same text again, then saved.  After checking the challenge again I was able to successfully validate the challenge.

Thanks for your help.
pconpcon
No problem.  Sometimes those async tooling requests can be a reail pain.