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
cptcpt 

Test method coverage

I am writing test method for my Apex web service but cant able to get 100% some warnings and 39 % only showing correct hoe to get clear the run test exactly .

 

In some Apex classes 2 lines not tested - showing 93% covered. but In some other classes it showing 19 lines not tested 37 % covered how to do clear and test  exactly  for 100% of classes

MohandaasMohandaas

To my knowledge you cant test a webservice methods.

 

To get a 100% coverage you need to test both positve and negative cases.

 

For example if your code,

if (a==b){

   do something;

}

else

{

   do something;

}

Make sure you write test method to satisfy both the case.

 

When you run the test from SFDC it will show the lines of code that is not covered. Make the required modifications to your test method to get the 100% coverage.

 

To run from UI goto setup-->develop-->apex classes

 

Select the class and click the button 'Run Test'. It will show the list of classes and the percentage coverage. Click the coverage to view the lines of codes not tested.

cptcpt

please can u Say how to check this following code in test method;.

 

Actually my code is inside the web service method:

 

global class YodleeLoginService {
webservice static String cobrandLoginContext(string username) {

 

 SitemmanagementYintegDomyexpensesComX.AddItemFormResponse addResult=addResponse.addInputItem(response, conversationSession, contentServiceId, sampleResponse);
        String id=addResult.itemId;
   
        cpt_dme__CreditCardItem__c item=new cpt_dme__CreditCardItem__c();
        item.cpt_dme__ItemId__c=addResult.itemId;
        item.cpt_dme__NickName__c=nickName;
        item.cpt_dme__UserName__c=userName;
      
        insert item;

 

My test method follows;

  cpt_dme__CreditCardItem__c item=new cpt_dme__CreditCardItem__c();
       String nickName;
       String userName;
        item.cpt_dme__ItemId__c='';
        item.cpt_dme__NickName__c='';
        item.cpt_dme__UserName__c='';
     
        if(item!=null)      
        insert item;

these lines are not covered error showing how to check this insertion of Credit Card Item by wrirting test method..