public static String httpJsonResponseString;
 HTTPResponse res_usage;
        res_usage = http_usage.send(req);
        HttpResponse res = new HttpResponse();
        res.setHeader('Content-Type', 'application/json');
        res_usage = res;

in this i am using condition is res.setbody(variable) this is running from test class, now how i satisfy this from test class?? i just want that json string is pass in this and get the value, how i can satisfy that because when i tried to do it with simple inserting the account then it is getting null pointer exception. Thanks!!

1 Answer 1


Test a Callout with HttpCalloutMock trailhead module is quite good in explaining on how to write proper test.

Also refer Testing HTTP Callouts by Implementing the HttpCalloutMock Interface.

  • But this is not a Mock callout..actually in this we are passing a hardcoded id in json string 'account_name":"20|20 Research","sf_account_id":"001d000001nBAwtAAG" like this, so just save from harcoded string we are using variable, so when i pass the value in this from test class then it get the value in this variable.
    Jan 22, 2018 at 10:53
  • and this is i don't know how to pass the value in variable from test class?
    Jan 22, 2018 at 10:53
  • With HttpCalloutMock, you don't need to skip the callout with Test.isRunningTest(). Its testing mock test in right way.
    – Raul
    Jan 22, 2018 at 10:58
  • yes may be you are right but this is not written by me, it is written by someone other and i need to create only test class of this, so i can't do any changes in main code...so can you please tell me the solution for this which i have posted?
    Jan 22, 2018 at 11:00
  • Have you had a look at the documentation attached? it clearly explains on how to write a test class for HTTP request callout. I didn't wanted to quote the whole documentation in the answer. Have already pointed you in right direction, I think.
    – Raul
    Jan 22, 2018 at 11:04

Not the answer you're looking for? Browse other questions tagged .