+ Start a Discussion
SRajesh8SRajesh8 

Class Generated by wsdl2apex (Test Class)

Hi

 

 

I have a webservices class and I generate a class from wsdl and now I need to write test class for it but here there are no methods in it and only having  variables and classes, here I wrote test class creating an object for each class and Inner class also but not covered it showing 0%.

 

 

can any one help in this plz

 

 

thanks

SRS

vishal@forcevishal@force

can you post the code for your class? That will make it easier for the people here to help you :)

SRajesh8SRajesh8

Hi Vishal,

 

 

Thanks to reply me and whcih I posted is not my code it just class found in  work book and I generate wsdl class for it and I need test class for it, Now I learning the how to write the test class and how to increasse the code coverage and here is the code

 

 

//Generated by wsdl2apex
//webservice class generated from Accountplan

public class soapSforceComSchemasClassAccountpla {
    public class LogInfo {
        public String category;
        public String level;
        private String[] category_type_info = new String[]{'category','http://soap.sforce.com/schemas/class/AccountPlan','LogCategory','1','1','false'};
        private String[] level_type_info = new String[]{'level','http://soap.sforce.com/schemas/class/AccountPlan','LogCategoryLevel','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://soap.sforce.com/schemas/class/AccountPlan','true','false'};
        private String[] field_order_type_info = new String[]{'category','level'};
    }
    public class AllowFieldTruncationHeader_element {
        public Boolean allowFieldTruncation;
        private String[] allowFieldTruncation_type_info = new String[]{'allowFieldTruncation','http://www.w3.org/2001/XMLSchema','boolean','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://soap.sforce.com/schemas/class/AccountPlan','true','false'};
        private String[] field_order_type_info = new String[]{'allowFieldTruncation'};
    }
    public class DebuggingHeader_element {
        public soapSforceComSchemasClassAccountpla.LogInfo[] categories;
        public String debugLevel;
        private String[] categories_type_info = new String[]{'categories','http://soap.sforce.com/schemas/class/AccountPlan','LogInfo','0','-1','false'};
        private String[] debugLevel_type_info = new String[]{'debugLevel','http://soap.sforce.com/schemas/class/AccountPlan','LogType','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://soap.sforce.com/schemas/class/AccountPlan','true','false'};
        private String[] field_order_type_info = new String[]{'categories','debugLevel'};
    }
    public class CallOptions_element {
        public String client;
        private String[] client_type_info = new String[]{'client','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://soap.sforce.com/schemas/class/AccountPlan','true','false'};
        private String[] field_order_type_info = new String[]{'client'};
    }
    public class AccountPlan {
        public String endpoint_x = 'https://ap1-api.salesforce.com/services/Soap/class/AccountPlan';
        public Map<String,String> inputHttpHeaders_x;
        public Map<String,String> outputHttpHeaders_x;
        public String clientCertName_x;
        public String clientCert_x;
        public String clientCertPasswd_x;
        public Integer timeout_x;
        public soapSforceComSchemasClassAccountpla.SessionHeader_element SessionHeader;
        public soapSforceComSchemasClassAccountpla.DebuggingInfo_element DebuggingInfo;
        public soapSforceComSchemasClassAccountpla.AllowFieldTruncationHeader_element AllowFieldTruncationHeader;
        public soapSforceComSchemasClassAccountpla.DebuggingHeader_element DebuggingHeader;
        public soapSforceComSchemasClassAccountpla.CallOptions_element CallOptions;
        private String SessionHeader_hns = 'SessionHeader=http://soap.sforce.com/schemas/class/AccountPlan';
        private String DebuggingInfo_hns = 'DebuggingInfo=http://soap.sforce.com/schemas/class/AccountPlan';
        private String AllowFieldTruncationHeader_hns = 'AllowFieldTruncationHeader=http://soap.sforce.com/schemas/class/AccountPlan';
        private String DebuggingHeader_hns = 'DebuggingHeader=http://soap.sforce.com/schemas/class/AccountPlan';
        private String CallOptions_hns = 'CallOptions=http://soap.sforce.com/schemas/class/AccountPlan';
        private String[] ns_map_type_info = new String[]{'http://soap.sforce.com/schemas/class/AccountPlan', 'soapSforceComSchemasClassAccountpla'};
        public soapSforceComSchemasClassAccountpla.Plan createAccountPlan(soapSforceComSchemasClassAccountpla.Plan vPlan) {
            soapSforceComSchemasClassAccountpla.createAccountPlan_element request_x = new soapSforceComSchemasClassAccountpla.createAccountPlan_element();
            soapSforceComSchemasClassAccountpla.createAccountPlanResponse_element response_x;
            request_x.vPlan = vPlan;
            Map<String, soapSforceComSchemasClassAccountpla.createAccountPlanResponse_element> response_map_x = new Map<String, soapSforceComSchemasClassAccountpla.createAccountPlanResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              '',
              'http://soap.sforce.com/schemas/class/AccountPlan',
              'createAccountPlan',
              'http://soap.sforce.com/schemas/class/AccountPlan',
              'createAccountPlanResponse',
              'soapSforceComSchemasClassAccountpla.createAccountPlanResponse_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.result;
        }
    }
    public class createAccountPlanResponse_element {
        public soapSforceComSchemasClassAccountpla.Plan result;
        private String[] result_type_info = new String[]{'result','http://soap.sforce.com/schemas/class/AccountPlan','Plan','1','1','true'};
        private String[] apex_schema_type_info = new String[]{'http://soap.sforce.com/schemas/class/AccountPlan','true','false'};
        private String[] field_order_type_info = new String[]{'result'};
    }
    public class SessionHeader_element {
        public String sessionId;
        private String[] sessionId_type_info = new String[]{'sessionId','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://soap.sforce.com/schemas/class/AccountPlan','true','false'};
        private String[] field_order_type_info = new String[]{'sessionId'};
    }
    public class createAccountPlan_element {
        public soapSforceComSchemasClassAccountpla.Plan vPlan;
        private String[] vPlan_type_info = new String[]{'vPlan','http://soap.sforce.com/schemas/class/AccountPlan','Plan','1','1','true'};
        private String[] apex_schema_type_info = new String[]{'http://soap.sforce.com/schemas/class/AccountPlan','true','false'};
        private String[] field_order_type_info = new String[]{'vPlan'};
    }
    public class DebuggingInfo_element {
        public String debugLog;
        private String[] debugLog_type_info = new String[]{'debugLog','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://soap.sforce.com/schemas/class/AccountPlan','true','false'};
        private String[] field_order_type_info = new String[]{'debugLog'};
    }
    public class Plan {
        public String name;
        public String planId;
        public Date planningPeriod;
        public Integer planNumber;
        private String[] name_type_info = new String[]{'name','http://www.w3.org/2001/XMLSchema','string','0','1','true'};
        private String[] planId_type_info = new String[]{'planId','http://soap.sforce.com/schemas/class/AccountPlan','ID','0','1','true'};
        private String[] planningPeriod_type_info = new String[]{'planningPeriod','http://www.w3.org/2001/XMLSchema','date','0','1','true'};
        private String[] planNumber_type_info = new String[]{'planNumber','http://www.w3.org/2001/XMLSchema','int','0','1','true'};
        private String[] apex_schema_type_info = new String[]{'http://soap.sforce.com/schemas/class/AccountPlan','true','false'};
        private String[] field_order_type_info = new String[]{'name','planId','planningPeriod','planNumber'};
    }
}

 

Once againg thanks

SRS

everlongheverlongh

Anyone answered this yet?

SRajesh8SRajesh8

Hi

 

Please share ur class in Apex code Developement Boards.

 

Regards,

Rajesh.

Kirill_YunussovKirill_Yunussov

Any luck, anyone?   I am about to open a case with Saelsfrorce about testing the Wsdl2Apex class.

GuyClairboisGuyClairbois

Hi Kirill,

I'm having the same issue. Looks like the wsdl2apex methods are not counted as being covered, even if you use the new WebServiceMock... Did you finally raise a case?

 

You could solve it by just creating a test class that specifically hits all the elements in the wsdl2apex, but that's a lot of work to create and maintain.

 

 

Kirill_YunussovKirill_Yunussov

This is what SF support replied with:

 

Hi Kirill, 

This is regarding the case# 08827550 . I called you, as you were not available so I left a voice mail. 

Having reviewed the case, I found that the apex code you are using is missing some important functionalities. So in order to resolve the issue, you need to refactor the apex class, containing the WSDL, especially into the methods like those build the web service request, invoke the web service, handle the HTTP response. And also there is a need to modify the test methods accordingly.

I am providing you the best practices which you should use in order to have the proper test method code coverage.

http://wiki.developerforce.com/page/An_Introduction_to_Apex_Code_Test_Methods

However I want to inform you that we recently made a change to the way we offer developer support to our customers and are sorry for the impact this may be having on you. We now provide developer support only to our premier customers and partners. If you have a developer support question, are looking for technical documentation, best practices, code samples and other ways to speed your development time, we have great resources that you can leverage within the developer community at http://developer.force.com/ <http://developer.force.com/>. 


GuyClairboisGuyClairbois

Hmm not really useful.. I am doing everything they describe and still the wsdl2apex code coverage is at 0%.

 

And besides that the documentation is outdated since it doesn't mention the mockservice.

 

Anyway, I guess I'll stick with the separate test class that just calls the wsdl2apex's methods 1 by 1 without really testing anything..

Andy FawcettAndy Fawcett

I've found the cause, there is an issue with the code coverage on the platform, if the test only invokes inner class methods, the coverage is not recorded. I've reproduced it via this, https://gist.github.com/afawcett/5521019 and plan to raise a Salesforce customer case to get them to resolve it.

 

You can workaround it by adding a default constructor to the generated code and making sure to call that in your test. You can also find a template for wrting a test class for a generated WSDL2Apex class here. I'll be blogging about this approach soon! https://github.com/financialforcedev/apex-mdapi/blob/master/apex-mdapi/src/classes/MetadataServiceTest.cls

GuyClairboisGuyClairbois

Thanks Andy, that's really useful information. I'll surely try this out.

 

Do keep us updated on SFDC's response to your case!

TomlToml
Thanks AndyInTheCload after digging through your code I was able to get the code coverage working.again for my WSDL generated class.