+ 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 );
    return MyPage;






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



classname objclass = new classname();



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 ,



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


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


             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>();
    String guid=CommonClass.getGuid();//getGuid();
    CommonCollections obj=new CommonCollections();
    String key=obj.getToken(guid); 
    Integer PageSize=obj.PageSize();

    service=serviceUrl+'listGetByTokenByPage?apitoken=' + key +'&pageNumber='+count+'&PageSize='+PageSize ;
        // add the endpoint to the request
    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)
    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');
        geo.lastRecord= element.getValue('LastRecord');
        geo.finalRecord= element.getValue('FinalPage');
        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+','