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
The PraxistThe Praxist 

No Apex test class named 'AnimalLocatorTest' was found.

Hi All,
Attempting the trailhead challenge for Apex REST Callouts. The class works and the test code also passes with 100% code coverage. However, trailhead is unable to find the AnimalLocatorTest class. Request please help.

AnimalLocator Class:
public class AnimalLocator {
    
    public static String getAnimalNameById(Integer ID) {
        
        String animal = ' ';
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        String s = string.valueOf(ID);
        request.setEndpoint('https://th-apex-http-callout.herokuapp.com/animals/'+ ID);
        request.setMethod('GET');
        HttpResponse response = http.send(request);
        Map<String,Object> animals = new Map<String,Object>();
        
        if(response.getStatusCode() == 200) {
            
            Map<String,Object> results = (Map<String,Object>)JSON.deserializeUntyped(response.getBody());
            animals = (Map<String,Object>) results.get('animal');         
            animal = String.valueOf(animals.get('name'));
        } else {
            
            system.debug(response.getBody());
            
        }
        Return animal;
        
    } 

}
AnimalLocatorMock Class:
@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":1,"name":"chicken","eats":"chicken food","says":"cluck cluck"}}');
        response.setStatusCode(200);
        return response;
    }
}

AnimalLocatorTest Class:
@isTest
private class AnimalLocatorTest {
    
    @isTest
    static void testGetCallout() {
        
        Test.setMock(HttpCalloutMock.class, new AnimalLocatorMock());
        
        String animalName = AnimalLocator.getAnimalNameById(1);
        system.debug('AnimalName : ' + animalName);
        System.assertEquals(animalName, 'chicken');
        
    }
    
}


 
Best Answer chosen by The Praxist
Amit Chaudhary 8Amit Chaudhary 8
Hi,

Is namespace or domain is enable in your org ?

Please check below post for same issue
1) https://developer.salesforce.com/forums/?id=906F0000000MJiPIAW
2) https://developer.salesforce.com/forums/?id=906F0000000MJiKIAW

Let us know if this will help you
 

All Answers

Amit Chaudhary 8Amit Chaudhary 8
Hi,

Is namespace or domain is enable in your org ?

Please check below post for same issue
1) https://developer.salesforce.com/forums/?id=906F0000000MJiPIAW
2) https://developer.salesforce.com/forums/?id=906F0000000MJiKIAW

Let us know if this will help you
 
This was selected as the best answer
The PraxistThe Praxist
Thanks Amit. The solution in the first link worked (i.e. deleted the class, created a new class, pasted the same code and checked challenge.