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
Ajosh JohnAjosh John 

help with a test class for an apex class which is referenced in a VF Page

Hi there. I have an VF page which is refernced to an apex class which basically references another VF page. Need help with a test class for this.

Visual Force Page where Apex Class is referenced:
<apex:page sidebar="false" lightningStylesheets="true">
<apex:form id="theForm">
 <div align="center">
  <apex:page controller="T_Dashboards">
<b><apex:commandbutton action="{!tradersummary}" value="Trader Summary"></apex:commandbutton></b>
<b><apex:commandbutton action="{!traderbook}" value="Trader Book"></apex:commandbutton></b>
<b><apex:commandbutton action="{!creditutilizationtrader}" value="Credit Utilization - Trader"></apex:commandbutton></b>
</apex:page>

Apex Class:
public class T_Dashboards {
public PageReference tradersummary() {

        PageReference pgref = new PageReference('/apex/TraderSummary');
        pgref.setRedirect(true);
        return pgref;
    }

public PageReference traderbook() {
        PageReference pgref = new PageReference('/apex/TraderBook');
        pgref.setRedirect(true);
        return pgref;
    }

public PageReference creditutilizationtrader() {
        PageReference pgref = new PageReference('/apex/CreditUtilizationTrader');
        pgref.setRedirect(true);
        return pgref;
    }
}

Test Class:
@isTest 
public class TestTDashboards{
public static testmethod void myunitTest(){    
Test.startTest();    
PageReference pageRef = Page.T_Dashboards;  
Test.setCurrentPage(pageRef);
T_Dashboards acontroller = new T_Dashboards();
PageReference pageRef1=acontroller.tradersummary();
Test.stopTest(); 
}
}
Best Answer chosen by Ajosh John
Deepak GerianiDeepak Geriani

Hello 
here is code 

@isTest 
public class TestTDashboards{
public static testmethod void myunitTest(){    
Test.startTest();    
PageReference pageRef = Page.TraderSummary;  
Test.setCurrentPage(pageRef);
T_Dashboards acontroller = new T_Dashboards();
PageReference pageRef1=acontroller.tradersummary();
Test.stopTest(); 
}
}

please copy and paste the above code and create different test method for each class function and set the page ref appropriate

mark as solved if your isssue is resolved. 
Thanks

All Answers

Deepak GerianiDeepak Geriani

Hello 
here is code 

@isTest 
public class TestTDashboards{
public static testmethod void myunitTest(){    
Test.startTest();    
PageReference pageRef = Page.TraderSummary;  
Test.setCurrentPage(pageRef);
T_Dashboards acontroller = new T_Dashboards();
PageReference pageRef1=acontroller.tradersummary();
Test.stopTest(); 
}
}

please copy and paste the above code and create different test method for each class function and set the page ref appropriate

mark as solved if your isssue is resolved. 
Thanks

This was selected as the best answer
Ajosh JohnAjosh John
Thanks Deepak. I was able to get a full 100% coverage on this. Appreciate your timely help!