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

how to write callout web services testclass programs in salesforce

Hi i deveop the webservices class program.but i want to develop the test class program.
how to do this....u have any reference code pls share with me.  Thanks
Grazitti TeamGrazitti Team

Test class cannot be used to test Web service callout. The Test.isRunningTest() method is a useful method to bypass web service callouts when running automated test cases that would otherwise fail.

For example:

public String sendHttpRequest() {
  HttpRequest req = new HttpRequest();

  Http http = new Http();
  if(!Test.isRunningTest()) {
    HttpResponse res = http.send(req);
    return res.getBody()
  } else {
    // You can prepare some simulated data for your test class here
    return simulatedData;


Grazitti Team.
Deepak Kumar ShyoranDeepak Kumar Shyoran
For that you have to create mock Test Class

Please visit it describe how to create test class for a class having web-service.

Please mark my answer as a best solution to your question to help others if it solves your problem.