You need to sign in to do that
Don't have an account?
Test method for batch class with webservice callouts
I have a batch class with callouts made to external webservice in the execute method. A schedular class passes records to this batch class at batch size of 1.
I am trying to write test method only for batch class. How do I call webservice methods inside the execute method? I used database.executeBatch method in test method, it covers part the execute method.. but stops at the line where the webservice call is made.
This is the webservice call made in the execute method. Passing the SoldCode to webservice and processing the response. The 2nd line is not covered in the code coverage part as I am not sure how to call this in the test method.
SalesforceCom_Live.SFDSPort stub_DS = new SalesforceCom_Live.SFDSPort();
SalesforceCom_Live.SFResponse_SFDS response_difot = stub_DS.SFDS(SoldCode);
SalesforceCom_Live is the Apex2WSDL Class.
SFDSPort is the method that has the endpoint, request and response elements.
SFResponse_SFDS is the response method in it.
In the test method, I have started with this.
Batch_DIFOT d = new Batch_DIFOT('select id .........); ID scheduleDIFOT = Database.executeBatch(d,1);
How do I call the 2nd line to proceed ?
help ?
Thanks.
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_callouts_wsdl2apex_testing.htm
You will then have to modify the code in the batch apex to check if the test is running then call the mock webservice else call the regular webservice mentioned by you.
The problem is I do not have a separate method for the Webservice callout in the batch class. The callouts are done in the Execute method itself.
So, as shown in the example, I cannot call the method explicitly.
WebSvcCallout.callEchoString('Hello World!');
Thats what I stated. You will need to create a new Mock Class with the implementation specified in the link above. Then try this:
I have added the code as per your suggestion, but in my mockwebservice i do not have the SFDS as a separate method hence it is giving error.
SalesforceCom_Live.SFResponse_SFDS response_difot = WebServiceMockImpl_DSWS.SFDS(SoldCode);
SFDS method doesn't exists
This is the webservice mock class I created before.
This is where I have been struck before too. Thanks for your patience.
Did you add this in the test class. This should call your test mock callout instead of the actual one:
SalesforceCom_Live.SFResponse_SFDS response_difot = WebServiceMockImpl_DSWS.SFDS(SoldCode);
The mock class doesnt have SFDS method.
Thanks!