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
Namit PalNamit Pal 

i want to write a test class for this vf page and constructor. How to proceed with this?

Hi everyone. I wish to write a test class for a vf page- custom controller. I am attaching both the codes for reference.

vf page:-
<apex:page standardController="Project_Mapping__c" extensions="MyProjectsPageController">
     <apex:pageBlock title="My Current Projects">
        <apex:pageBlockTable value="{!ListCurrentProjects}" var="Current">
            <apex:column >
                <apex:facet name="header">Project Name</apex:facet>
                <apex:outputText value="{!Current.Project__r.Name}"/>
            </apex:column>
            <apex:column >
                <apex:facet name="header">Project Start Date</apex:facet>
                <apex:outputText value="{!Current.Resource_Start_Date__c}"/>
            </apex:column>
            <apex:column >
                <apex:facet name="header">Project End Date</apex:facet>
                <apex:outputText value="{!Current.Resource_End_Date_del__c}"/>
            </apex:column>
            <apex:column >
                <apex:facet name="header">Status</apex:facet>
                <apex:outputText value="{!Current.Project__r.Status__c}"/>
            </apex:column>
        </apex:pageBlockTable>
    </apex:pageBlock>
     <apex:pageBlock title="My Previous Projects">
        <apex:pageBlockTable value="{!ListPreviousProjects}" var="Previous">
            <apex:column >
                <apex:facet name="header">Project Name</apex:facet>
                <apex:outputText value="{!Previous.Project__r.Name}"/>
            </apex:column>
            <apex:column >
                <apex:facet name="header">Project Start Date</apex:facet>
                <apex:outputText value="{!Previous.Resource_Start_Date__c}"/>
            </apex:column>
            <apex:column >
                <apex:facet name="header">Project End Date</apex:facet>
                <apex:outputText value="{!Previous.Resource_End_Date_del__c}"/>
            </apex:column>
             <apex:column >
                <apex:facet name="header">Status</apex:facet>
                <apex:outputText value="{!Previous.Project__r.Status__c}"/>
            </apex:column>
        </apex:pageBlockTable>
    </apex:pageBlock>
     <apex:pageBlock title="My Future Projects">
        <apex:pageBlockTable value="{!ListFutureProjects}" var="Future">
            <apex:column >
                <apex:facet name="header">Project Name</apex:facet>
                <apex:outputText value="{!Future.Project__r.Name}"/>
            </apex:column>
            <apex:column >
                <apex:facet name="header">Project Start Date</apex:facet>
                <apex:outputText value="{!Future.Resource_Start_Date__c}"/>
            </apex:column>
            <apex:column >
                <apex:facet name="header">Project End Date</apex:facet>
                <apex:outputText value="{!Future.Resource_End_Date_del__c}"/>
            </apex:column>
            <apex:column >
                <apex:facet name="header">Status</apex:facet>
                <apex:outputText value="{!Future.Project__r.Status__c}"/>
            </apex:column>
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>


controller:-
User-added image

PawanKumarPawanKumar
Please share your controller code as text.
PawanKumarPawanKumar
Please try below.

--------------------------------------------
@isTest
private class MyProjectsPageControllerTest {
 static testMethod void testCnt() {
  Project_Mapping__c pm = new Project_Mapping__c();
  //You can set your other required field.
  //pm.Name='TestMap';
  insert pm;

  MyProjectsPageController controller = new MyProjectsPageController(new ApexPages.StandardController(pm));
  List < Project_Mapping__c > cProjectsList = controller.ListCurrentProjects;
  //System.assertEquals(0,cProjectsList.size());
  List < Project_Mapping__c > pProjectsList = controller.ListPreviousProjects;
  //System.assertEquals(0,pProjectsList.size());
  List < Project_Mapping__c > fProjectsList = controller.ListFutureProjects;
  //System.assertEquals(0,fProjectsList.size());
 }
}

Regards,
Pawan Kumar