You need to sign in to do that
Don't have an account?
Gaurav Agnihotri
Test class for WSDLToApex Class
I was able to create a apex classes from WSDL. Now, I need to create a test class for code coverage. This requires doing a mock call to the web service. I am having difficultly creating test classes.
3. Finally, I created a test class to fake a response to be generated
Regards,
Gaurav
- First I started with a class that implements WebServiceMock. In this class I created a response element, populated it and add response element.
@isTest global class WebServiceTestMock implements WebServiceMock { global void doInvoke( Object stub, Object request, Map<String, Object> response, String endpoint, String soapAction, String requestName, String responseNS, String responseName, String responseType) { //Create Response element form the autogenerated class. tempuriOrg.ProcessWarehouseInventoryResponse_element request_x = new tempuriOrg.ProcessWarehouseInventoryResponse_element(); //populate response element tempuriOrg.ProcessWarehouseInventoryResponse_element response_x; //Add response element to the reponse parameter response.put('response_x', response_x); } }2. Next, I created a new class that populates end point and invokes EchoString Method
public class WebServiceCallout { public static String callEchoString(String input) { tempuriOrg.QantelDataServiceEndPoint.endpoint_x = 'http://api.salesforce.com/foo/bar'; // This invokes the EchoString method in the generated class String echo = sample.EchoString(input); return echo; } }
3. Finally, I created a test class to fake a response to be generated
@isTest private class WebSvcCalloutTest { @isTest static void testEchoString() { // This causes a fake response to be generated Test.setMock(WebServiceMock.class, new WebServiceTestMock()); // Call the method that invokes a callout //String output = WebServiceCallout.callEchoString('Hello World!'); // Verify that a fake result is returned //System.assertEquals('Mock response', output); } }Please help me out or point me to the right resource !!
Regards,
Gaurav
This looks like you generated it using the FuseIT SFDC Explorer Wsdl2Apex tool (http://www.fuseit.com/explorer). Part of this tool includes the option to generate the Mock and associated test classes for you. It won't be an exhaustive test of the web service, but it will give you coverage of the generated code.
On the Tab where you are selecting the methods to generate code for, check the "Generate Test Classes" button in the toolbar.
From your example code, you want something like this in your test case to call the web service.
All Answers
This looks like you generated it using the FuseIT SFDC Explorer Wsdl2Apex tool (http://www.fuseit.com/explorer). Part of this tool includes the option to generate the Mock and associated test classes for you. It won't be an exhaustive test of the web service, but it will give you coverage of the generated code.
On the Tab where you are selecting the methods to generate code for, check the "Generate Test Classes" button in the toolbar.
From your example code, you want something like this in your test case to call the web service.
yes, I used FuseIT to generate classes. I was able to create a test class too and was able to get a code coverage. I will use your sample code to perform WebSvrCallout Test.
Appreciate your help.