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
Aditi Mohanty 5Aditi Mohanty 5 

I want test class for this code with 100 % coverage

public class postalcode {
    @AuraEnabled
    public static List<Object> call(String p)
    {
        List<object> post=new List<object>();
        
        String s='';
        List<Object> office=new List<Object>();
        List<String> name=new List<String>();
        object o;
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        request.setEndpoint('https://api.postalpincode.in/pincode/'+p);
        request.setMethod('GET');
        HttpResponse response = http.send(request);
        if (response.getStatusCode() == 200) {
           
			List<Object> lst_JsonParse = (List<Object>)Json.deserializeUntyped(response.getBody());
            
            for(Object obj : lst_JsonParse)
             {
                 Map<String,Object> mp_StrObj = (Map<string,Object>)obj;
                office=(List<object>)mp_StrObj.get('PostOffice');
        
            }
            for(object o2:office){
                map<String,object> fin=(Map<String,Object>)o2;
               	String a=(String)fin.get('Name');
                name.add(a);
                System.debug(a);
            }

        }
        return office;
    }
}

 
AbhishekAbhishek (Salesforce Developers) 
Try the suggestions mentioned in the below blogs,

https://blogs.infosupport.com/thinking-about-test-coverage/

https://stackoverflow.com/questions/1475520/unit-testing-code-coverage-do-you-have-100-coverage


It might help you
Aditi Mohanty 5Aditi Mohanty 5
I want test class for callouts. I am facing error " no content to map due to end of input". Test class is covering upto line "List<Object> lst_JsonParse = (List<Object>)Json.deserializeUntyped(response.getBody());", but not after that.
I want help in this.