You need to sign in to do that
Don't have an account?
The 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:
AnimalLocatorTest Class:
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'); } }
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
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