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
Pete Watson 5Pete Watson 5 

Test Class for Custom Controller (Visualforce Page - Gantt Chart)

public class ProjectGanttXChart {
	public List<String> Name{get;set;}
    public List<String> SDate{get;set;}
    public List<String> EDate{get;set;}
    public List<Integer> Duration{get;set;}
    public List<String> Project{get;set;}
    
    public ProjectGanttXChart(){
        List<Case> caseList = new List<Case>();
        Name = new List<String>();
        SDate = new List<String>();
        EDate = new List<String>();
        Duration = new List<Integer>();
        Project = new List<String>();
        
        Integer dd;
        Integer month;
        Integer year;
        
        caseList = [SELECT Id, Project_Name__c, CreatedDate, Status, Start_Date__c, Completion_Date__c FROM Case WHERE Is_Project__c = true];     
        for(Case c:caseList){
            Date todayDate = c.Start_Date__c;
            dd = todayDate.day();
            month=todayDate.month();
            year = todayDate.year();
            Name.add(c.Project_Name__c);
            SDate.add(year+'-'+month+'-'+dd);
            dd = c.Completion_Date__c.day();
            month= c.Completion_Date__c.month();
            year = c.Completion_Date__c.year();
            EDate.add(year+'-'+month+'-'+dd);
            Integer dt = (c.Start_Date__c).daysBetween(Date.valueOf(c.Completion_Date__c));
            Duration.add(dt);
        }
    }
}

Hi, thanks for looking over my question, much appreicated! 

I am having trouble creating a test class for this custom controller to a visualforce page (to present a gantt chart) so I would be very greatfull for any assistance as I need to deploy to prod asap. 

Many thanks
Pete


 
AnudeepAnudeep (Salesforce Developers) 
Let me know if this gives you any coverage
 
@isTest
private class TestProjectGanttXChart{
    @isTest
    private static void testClass()
    {
	TestProjectGanttXChart controller = new TestProjectGanttXChart();
    Case cs = new Case(); 
    cs.Project_Name__c = 'project_name'; 
    cs.CreatedDate = system.today(); 
    cs.Status = 'status'; 
    cs.Completion_Date__c = System.today().addDays(-1);
    cs.Is_Project__c = true; 
    insert cs; 
    }
}

 
Pete Watson 5Pete Watson 5
Thanks very much Anudeep, I tried similar but as with the above getting 0% coverage, its worth noting sorry that is_project__c is a formula field.