You need to sign in to do that
Don't have an account?

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();
}
}
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();
}
}
Hello
here is code
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
Hello
here is code
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