You need to sign in to do that
Don't have an account?
Unit testing of json parser
How do i do the unit testing for this.Unit testing does not go into this part.
it is not being tested from response.getbody().
We are doing a lot of json parsing please do help
Shine
************Code*******************
JSONParser parser = JSON.createParser(response.getBody());
while (parser.nextToken() != null)
{
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'total_records'))
{
// Get the value.
parser.nextToken();
// Compute the grand total price for all invoices.
total_records=integer.valueof(parser.getText());
// total_records=
}
************Code*******************
You need to create a response object with a body that contains JSON with a "total_records" field.
How are you currently unit testing the method that contains this code? You have to create a fake HttpResponse object, since test cases don't send HTTP requests, right?
If you look at the Apex documentation on Testing HTTP Callouts, it shows you how to do it.
All Answers
You need to create a response object with a body that contains JSON with a "total_records" field.
How are you currently unit testing the method that contains this code? You have to create a fake HttpResponse object, since test cases don't send HTTP requests, right?
If you look at the Apex documentation on Testing HTTP Callouts, it shows you how to do it.