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
Akshay JuwaAkshay Juwa 

How to write a test class for my class?

I'm new to the salesforce. Does anybody know how to write a test class for the following?

public class JokeApiService {
    
    public static List<JokeApiService.JokeWrapper> getJoke(String type) {
        String url = System.Label.Joke_API_URL; 
        try {
            Http http = new Http();
            HttpRequest req = new HttpRequest();
            //10 is the max number of jokes that can be called at once 
            req.setEndpoint(url+type+'?type=single&safe-mode&amount=10');
            req.setMethod('GET');
            HttpResponse res = http.send(req); 
            Map<String, Object> results = (Map<String, Object>)JSON.deserializeUntyped(res.getBody());
            String serializedJokes = JSON.serialize(results.get('jokes')); 
            List<JokeApiService.JokeWrapper> jokes = (List<JokeApiService.JokeWrapper>) JSON.deserialize(serializedJokes, List<JokeApiService.JokeWrapper>.class);
            return jokes;
        } catch (Exception e) {
            System.debug(e.getMessage()); 
            return null; 
        }
    }

    public class JokeWrapper { 
        public String category;
        public String type;
        public String joke;
    }
}
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Akshay,

Can you provide details llike what is the url that you have in Joke_API_URL Label?

Thanks,