Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

My Apex class

public with sharing class helpTextClass {
  public string main(string url)
    {

            Http h = new Http();    
            HttpRequest req = new HttpRequest();
            req.setEndpoint(url);
            req.setMethod('GET');
            req.setTimeout(60000);
            string hresult='';
             if(isValid==true)
            {
                HttpResponse hres = h.send(req);
                hresult = hres.getBody();
                //system.debug('------'+hresult);
            }else{
                hresult = '<?xml version="1.0" encoding="ISO-8859-1"?><HelpTextDetails><BaseURL>http://click-pledge.v-empower.com/web/HelpText/HelpTextXml</BaseURL><HelpTab TabName="C&P InvoicePayment" label="C&P InvoicePayment"><TabSection Name="C&P InvoicePayment"></TabSection></HelpTab></HelpTextDetails>';

            }           
            return hresult;
         }
       public class subTabnames{
        public string description{get;set;}
        public string link{get;set;}
        public string video{get;set;}
    }   
public  map<string,map<string,subTabnames>> helpText(){
     finalMap = new map<string,map<string,subTabnames>>();
      url = 'http://click-pledge.v-empower.com/web/HelpText/HelpTextXml/HelpTextXml.xml';
        isValid=true;           
        try{    
            helpXml = main(url);
        }catch(System.CalloutException e){
            system.debug('Error: '+e);
        }


     Dom.document doc = new Dom.document();
       doc.load(helpxml);
       Dom.XMLNode elementsList = doc.getRootElement();
        if(elementsList !=NULL){
             for(Dom.XMLNode child : elementsList.getChildElements()) { 
                 boolean checkcategory = false;
                 // Some code here
              }
       }       
      return finalmap;

}   

My Test Class for this is

@istest
public class test_helpTextPage{
    public static testmethod void helptest(){
        helptextclass hc = new helpTextClass();      
         helpTextclass.subTabNames tabNames = new helpTextclass.subTabnames();        
        hc.main('http://click-pledge.v-empower.com/web/HelpText/HelpTextXml/HelpTextXml.xml');
        hc.isValid = true;      
         hc.helpText();  
    }
}

the code coverage for this is 53% and it is not covering this Part

 Dom.document doc = new Dom.document();
       doc.load(helpxml);
       Dom.XMLNode elementsList = doc.getRootElement();
        if(elementsList !=NULL){
             for(Dom.XMLNode child : elementsList.getChildElements()) { 
                 boolean checkcategory = false;
                 // Some code here
              }
       }       
      return finalmap;

What should I do to cover this also.Help Pls!!!!!!

share|improve this question
add comment

1 Answer

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_restful_http_testing_httpcalloutmock.htm

You have to implement mock callouts for this .In test class the actual call wont be made and hence mock interface you can use to achieve code coverage.

refer this thread :Testing WebServiceCallout with HttpCalloutMock

caution:Testing HttpCallout with HttpCalloutMock and UnitTest Created Data

There is known issue of Pending DML statements

Refer the blog:

http://blogs.developerforce.com/developer-relations/2012/10/testing-http-callouts-with-static-data-in-winter-13.html#comment-688228232

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.