+ Start a Discussion
.Net Api.Net Api 

How to write Test Cases

HI ,

         How to write the test cases for my below method and the test case should cover the 75% coverage ,how to do it  can please any one help me in this issue

 

public PageReference redirectLists()
{
    //This takes referece id

    String Key=getGuid();
    // this is used to create the object for redirection

    RedirectUrl objRedirectUrls = new RedirectUrl();  
  // This gets the key from the the class

    listUrl =  objRedirectUrls.getListUrl(Key);

   // This is is used to redirect the page

    pagereference MyPage=  new PageReference(listUrl );
    MyPage.setRedirect(true);
    return MyPage;
 }

 

 

Regards,

Kranthi

kiranmutturukiranmutturu

create an instance of the class of the respective method.. and call the method like...

 

 

classname objclass = new classname();

objclass.redirectLists();

 

then that method will cover...

.Net Api.Net Api

Dear kiran

                   We have done as you said but the over all code coverage is coming only 35% only ,we are not unable to reach the 100%, we require maximum over all  75% code coverage ,so please let me know how we can solve this issue or please advice us how we can appraoch any best practice ,please let me know if you any queries to be more clear

 

 

Regards ,

Kranthi

kiranmutturukiranmutturu

your production environment is giving only 35% na? this is not a good practise ....check it out by using apex test execution in the develop section.......and find the percentage covered of all the classes ..and try to write the best coverage for all the classes and move them to prodcution....

.Net Api.Net Api

No in my development box it is coming 35% to deploy into production we need to have 75%  please let me know  how can do the best practice code coverage

kiranmutturukiranmutturu

its not required that ur dev box should have 75% code coverage to move from dev to prod.. but prod must have 75%....

.Net Api.Net Api

Kiran,

             I need to write test case for the below method please advice how can we do this .

 

 

 

/Code for calling websercice to get username and token starts

//public List<GeoResult> output()
public List<GeoResult> output(Integer count)
{
    HttpRequest req = new HttpRequest();
    Http http = new Http();
    List<GeoResult> results = new List<GeoResult>();
   
    req.setMethod('GET');
    String guid=CommonClass.getGuid();//getGuid();
    CommonCollections obj=new CommonCollections();
    String key=obj.getToken(guid); 
    Integer PageSize=obj.PageSize();

    serviceUrl=obj.getServiceURL();         
 
    service=serviceUrl+'listGetByTokenByPage?apitoken=' + key +'&pageNumber='+count+'&PageSize='+PageSize ;
 
        // add the endpoint to the request
    req.setEndpoint(service);
    HTTPResponse resp = http.send(req);
    XmlDom doc = new XmlDom(resp.getBody());       
    XmlDom.Element[] elements = doc.getElementsByTagName('Result');
    if (elements != null) {
        for (XmlDom.Element element : elements)
            results.add(toGeoResult(element));
        }
    return results;
 
}


private GeoResult toGeoResult(XmlDom.Element element) {
        GeoResult geo = new GeoResult();
        geo.lName= element.getValue('listname');      
        geo.mDate= element.getValue('modifiedDate');      
        geo.Count= element.getValue('Count');      
        geo.listid= element.getValue('listid');
         geo.TotalCount= element.getValue('TotalCount');
        iTotalRecordsCount=Integer.ValueOf(geo.TotalCount);
        geo.lastRecord= element.getValue('LastRecord');
        iLastRecord=Double.ValueOf(geo.lastRecord);
        geo.finalRecord= element.getValue('FinalPage');
        iFinalPageSize=Integer.ValueOf(geo.finalRecord);
        return geo;      
      
    }
   
private class GeoResult {
    public String lName{get;set;}
    public String mDate{get;set;}
    public String Count{get;set;}
    public String listid{get;set;}
     public String TotalCount{get;set;}
    public String lastRecord{get;set;}
    public String finalRecord{get;set;}
   
     public String toDisplayString() {
     return lName+ ', '
            + mDate+ ', '
            + Count+','
            +listid;

       
}
}