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
MnZ321MnZ321 

Need help with code coverage.

I'm unable to have code coverage. Wrote a test class that has 24% coverage. How should I test loops and conditional statements?
public class OrderTrackingList{
    public OrderTrackingList(ApexPages.StandardController controller) {}
    public list<wrapgroupwise> singlegroup;
    public List<wrapgroupwise> getStartHere(){
    singlegroup= new List<wrapgroupwise>();
    List<orders__c> tempacc=[SELECT Id,Name FROM orders__c where id=:ApexPages.currentPage().getParameters().get('id')];
 
     for(Integer i=0; i<tempacc.size() ; i++){
        List <order_lines__c> tempOrderLines=[SELECT Id,name From order_lines__c Where order_number__c=:tempacc[i].id];
        List <shipment_lines__c> tempShipmentLines=[SELECT Id,Name From shipment_lines__c Where Order_Number__c=:tempacc[i].id];
         
      if(tempOrderLines.size()==0 && tempShipmentLines.size()==0){
              singlegroup.add(new wrapgroupwise(tempacc[i],null,null)); 
        }
        else{
         
         if(tempShipmentLines.size()==0)
         {
              if(tempOrderLines[i].status__c=='Open')
               {
                   tempOrderLines[i].calculated_estimated_delivery_date__c=tempOrderLines[i].planned_ship_date__c;
               }
                                 
            singlegroup.add(new wrapgroupwise(tempacc[i],tempOrderLines,null)); 
                  
          }   
         else
         {
    
           if(tempOrderLines[i].status__c=='Open')
           {
               tempOrderLines[i].calculated_estimated_delivery_date__c=tempOrderLines[i].planned_ship_date__c;
           }
           if(tempOrderLines[i].status__c=='Invoiced')
           {
               tempOrderLines[i].calculated_estimated_delivery_date__c=tempShipmentLines[i].estimated_delivery_date__c;
           }
           if(tempOrderLines[i].status__c=='Shipped but not billed')
           {
               tempOrderLines[i].calculated_estimated_delivery_date__c=tempShipmentLines[i].estimated_delivery_date__c;
           }           
     
          singlegroup.add( new wrapgroupwise(tempacc[i],tempOrderLines,tempShipmentLines)); 
         }
    
        }
       }
      return singlegroup; 
      }
     public class wrapgroupwise
     {
        public List<order_lines__c> con {get;set;}
        public orders__c acc {get;set;}
        public List<shipment_lines__c> opp {get;set;}
    
         public wrapgroupwise( orders__c a , list<order_lines__c> c,list<shipment_lines__c> o)
         {
            acc=a;
            con=c;
            opp=o;
          } 
      } 
     }
> ========================TEST CLASS===========================
@isTest
     public class GE_PW_OrderTrackingList_Test{ 
    static testMethod void coverCode(){
             
              //GE_PW_OrderTrackingList.wrapgroupwise wgw = new            GE_PW_OrderTrackingList.wrapgroupwise();
              Profile pf= [SELECT Id FROM Profile WHERE name= 'System Administrator' LIMIT 1];
              
              Account acc = new Account(Name='ABC Corp.');
              insert acc;
              System.assertEquals('ABC Corp.', acc.name);
              
              gew_orders__c tempOrder = new gew_orders__c();
              tempOrder.name = '0001234567';
              tempOrder.gew_account__c = acc.id;
              insert tempOrder;
              System.assertEquals('0001234567', tempOrder.name);
              
             
              gew_order_lines__c tempOL = new gew_order_lines__c();
              tempOL.Name = '10';
              tempOL.gew_number_of_order_lines__c = tempOrder.id;
              insert tempOL;
              System.assertEquals('10', tempOL.name);
              
              gew_shipment_lines__c tempSL = new gew_shipment_lines__c();
              tempSL.Name = '10'; 
              tempSL.CurrencyIsoCode = 'USD'; 
              insert tempSL;
              
              System.assertEquals('USD', tempSL.CurrencyIsoCode);
 
             GE_PW_OrderTrackingList gepwO = new GE_PW_OrderTrackingList(new ApexPages.StandardController(tempOrder));  
        	 GE_PW_OrderTrackingList gepwOL = new GE_PW_OrderTrackingList(new ApexPages.StandardController(tempOL));
             GE_PW_OrderTrackingList gepwSL = new GE_PW_OrderTrackingList(new ApexPages.StandardController(tempSL));
 			 gepwO.getStartHere();
             //gepwOL.singlegroup.add(gepwOL);
        	// gepwSL.singlegroup.add(gepwSL);
            // gepwO.singlegroup.add(gepwO);
            }
       }

What am I missing? Please guide.
Thanks.

BHinnersBHinners
Here is a great document for info on testing Visualforce controllers: http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_error_handling.htm
And some basics for unit testing: https://developer.salesforce.com/page/An_Introduction_to_Apex_Code_Test_Methods  Near the bottom of the page, you will find a great example for testing controllers.

My preference after setting up data is to instantiate the controller class and then to call methods and properties directly from the original code, like what you see in the sample code under "Test Methods and Visualforce Controllers" on the Introduction page I linked above.