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
Tavva Sai KrishnaTavva Sai Krishna 

Test class for Json response

Hi guys, 
         I have created a class which has callout & it need to fetch the response from the google server. By using JSON parser, I am  getting the latitude & longitude values which are present in the response. For that I used Below Code to access the Latitude & longitude values
JSONParser parser = JSON.createParser(JSonText);
            double lat = null;
            double lon = null;
            while (parser.nextToken() != null)
             {
                if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && 
                    (parser.getText() == 'location'))
                    {
                       parser.nextToken(); // object start
                       while (parser.nextToken() != JSONToken.END_OBJECT)
                       {
                           String txt = parser.getText();
                           parser.nextToken();
                           if (txt == 'lat')
                               lat = parser.getDoubleValue();
                           else if (txt == 'lng')
                               lon = parser.getDoubleValue();
                       }
                    
                    }
             }

 But I was unable to write the test class which covers these lines.. My test coverage is 66% as of now.. Please Help me , in writing the test class to cover all above lines should cover....

Thanks
Best Answer chosen by Tavva Sai Krishna
Tavva Sai KrishnaTavva Sai Krishna
Hi All, 
    Please look in to this post which has been already solved for this same Question. But for other users it might help so I am not deleting this post.... The url is  https://developer.salesforce.com/forums/ForumsMain?id=906F000000091aWIAQ