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
chubsub2chubsub2 

Need Help Writing Test Class for Custom Controller on a Visualforce Page

I'm only getting 14% coverage with the test method below, any advise?

 

Visualforce page:

<apex:page controller="CustomPage" showHeader="true" >
<table>
<tr>
<td>
<apex:dataTable value="{!List}" var="r">
<apex:column value="{!r.Name}"/>
</apex:dataTable>
</td>
</tr>
</apex:page>

 

 

Controller:

public class IngList {
  // ApexPages.StandardSetController must be instantiated  
    
  // for standard list controllers  
    
    public ApexPages.StandardSetController setCon {
        get {
            if(setCon == null) {
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
                      [select name, from CustomObject__c WHERE custom_check_box_field__c = true]));
            }
            return setCon;
        }
        set;
    }

    // Initialize setCon and return a list of records  
    
    public List<CustomObject__c> getList() {
         return (List<CustomObject__c>) setCon.getRecords();
    }
}

 

 

 

 

Test Class:

@isTest

private class TestIngList {

static testMethod void testIngList(){
    ApexPages.StandardSetController setCon;
    PageReference pageRef = Page.CustomPage;

Custom_Object__c cusobj = new Custom_Object__c();
cusobj.custom_check_box_field__c = true;
insert cusobj;

List<CustomObject__c> cus = new List<Custom_Object__c>{};

System.assertNotEquals(null, cusobj.Id);
    Test.setCurrentPage(pageRef);
    IngList controller = new IngList();

}
}

 

 

Thanks in Advance!

WizradWizrad

If you are running tests within the UI click the percent and it will show you exactly which lines are not getting covered.

 

If you are using eclipse expand the "Code Coverage Results" section for the equivalent information.

chubsub2chubsub2

Here's an image of the errors, I'm just not sure how to write the test coverage for those particular lines in Red.