You need to sign in to do that
Don't have an account?

No Apex class named 'AnimalLocatorMock' was found. Apex REST callouts unit
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;
}
}
@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;
}
}
Check this out.
Code for AnimalLocator apex class
Code for Test Class - AnimalLocatorTest
Code for AnimalLocatorMock
Thanks,
Santhosh