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

Create dummy response in test class for webservice callout class

Need help in writing test class for class that makes webservice callout. Only the dummy response part isn't working.
As suggested by other users, I have created a static variable in test class and used it in the original class also. So, while running the test class, the callout is by-passed successfully.
Below is the code coverage part. As you can see in the image, I am successfully by-passing the callout in Line 120.
But from Line 127 onwards, it is not covered as responseList is empty.
I have created the dummy response in the test class. Is this the correct way of creating the dummy response? Or do I need to make any changes in creating dummy response?
Here's the test class code.

//setting the static variable to true, so it wont enter in the real webservice class
//calling the webservice class
BatchKeyAccountsWS d = new BatchKeyAccountsWS('select id FROM Account Order by CreatedDate DESC LIMIT 1'); 
ID scheduleC = Database.executeBatch(d,1);
//instantiating the wsdl2apex class
nshSalesforce.SF_InPort stub = new nshSalesforce.SF_InPort(); 
//Creating dummy response List
List<nshSalesforce.Item_element> responseList = new List<nshSalesforce.Item_element>(); 

nshSalesforce.Item_element response = new nshSalesforce.Item_element();


 Please help
Arun MKArun MK



Try to make use of the WebServiceMock Interface class.


Follow this link. It will b helpful.


If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.




But mine is batch apex. Any example of test class for batch apex class with webservice callouts.