You need to sign in to do that
Don't have an account?

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
how to do this....u have any reference code pls share with me. Thanks
Please go thorugh this link : https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_callouts_wsdl2apex_testing.htm
Thanks,
N.J
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();
req.setEndpoint(endpointUrl);
req.setMethod(method);
req.setBody(bodyStr);
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;
}
}
Thanks,
Grazitti Team.
Please visit https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_callouts_wsdl2apex_testing.htm 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.