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
Wayne_ClarkWayne_Clark 

Need Help with Testing Controller Extension only 60% covered

Aloha,

 

I'm having trouble testing out this line of code:

 

    public List<Order_Dimension__c> getdimList() {
            return dimList;
      }

 

 

Below is the full controller and test method so far, but only 60% is covered and the lines above are marked in red as not being tested.

 

 

public with sharing class OrderExtension{
    
    
    private final List<Order_Dimension__c> dimList;
    
    public OrderExtension(ApexPages.StandardController controller)     
        {
        dimList = [select e.Name, e.Commodity_Description__c, e.Length_Feet__c, Length_Inches__c, Width_Feet__c, Width_Inches__c, Height_Feet__c, Height_Inches__c, Classification__c, Dimensions__c
        from Order_Dimension__c e where Order__c=:ApexPages.currentPage().getParameters().get('id') 
        ];
    }
        
    public List<Order_Dimension__c> getdimList() {
            return dimList;
      }
  
}

 

@isTest

private class TestOrderExtension {

static testMethod void testOrderExtension(){
   Order__c order;
   ApexPages.StandardController sc;
   OrderExtension ore;

Account account = new Account();// specify all the required fields
account.name = 'testing';
account.shippingcity = 'baltimore';
account.shippingstate = 'MD';
account.shippingcountry = 'USA';
account.shippingpostalcode = '21228';
insert account;
Contact contact = new Contact();// specify all the required fields
contact.lastname = 'test';
insert contact;
States__c state = new States__c ();
state.State_Code__c = 'BB';
insert state;
Order__c ord = new Order__c ();
ord.Account__c = account.Id;
insert ord;
Order_Dimension__c dim = new Order_Dimension__c ();
dim.order__c = order.Id;
dim.Commodity_Description__c = 'steel';
dim.Classification__c = 'new';
dim.Height_Feet__c = Decimal.valueOf('1');
dim.Height_Feet__c = Decimal.valueOf('1');
dim.Length_Feet__c = Decimal.valueOf('1');
dim.Length_Inches__c = Decimal.valueOf('1');
dim.Width_Feet__c = Decimal.valueOf('1');
dim.Width_Inches__c = Decimal.valueOf('1');


System.assertNotEquals(null, ord.Id);//tests to see if your insert was successful
   ore = new OrderExtension(new ApexPages.StandardController(ord)); //here you instantiate the controller with a standard controller.
   //start you user testing.




}

}

 

 

Best Answer chosen by Admin (Salesforce Developers) 
BritishBoyinDCBritishBoyinDC

I don't think you're ever inserting the Order Dimension record in your test?

 

To test the get statement, just add this line after you instantiate the extension...

ore.getdimlist();

 

All Answers

BritishBoyinDCBritishBoyinDC

I don't think you're ever inserting the Order Dimension record in your test?

 

To test the get statement, just add this line after you instantiate the extension...

ore.getdimlist();

 

This was selected as the best answer
Wayne_ClarkWayne_Clark

Thanks! I knew it was something simple.