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

help for test case
this is the controller i have written and plz help me how to write test case
Public class Remarkscontroller { public Appointment__c[] blockedappts {get; set;} String m_param; String y_param; Date Di = system.today(); Public Integer monthc {get;set;} public Integer Year{get; set;} Public string monthname {get;set;} public Remarkscontroller(Dev_Appt_Calendar_Repeat controller) { m_param = System.currentPageReference().getParameters().get('br'); y_param = System.currentPageReference().getParameters().get('dr'); Monthc = di.month(); Year= di.year(); if(Monthc == 12){ monthname = 'December'; } if(Monthc == 11){ monthname = 'November'; } if(Monthc == 10){ monthname = 'October'; } if(Monthc == 9){ monthname = 'September'; } if(Monthc == 8){ monthname = 'August'; } if(Monthc == 7){ monthname = 'July'; } if(Monthc == 6){ monthname = 'June'; } if(Monthc == 5){ monthname = 'May'; } if(Monthc == 4){ monthname = 'April'; } if(Monthc == 3){ monthname = 'March'; } if(Monthc == 2){ monthname = 'Febuary'; } if(Monthc == 1){ monthname = 'January'; } //blockedappts = [select id,appt_date__c,Calander_Day__c,Appt_remarks__c,Block_the_Entire_Day__c from Appointment__c where Block_the_Entire_Day__c=TRUE AND Recordtypeid=:'01290000000YnZw' AND CALENDAR_YEAR(Appt_date__c) =:Year AND CALENDAR_MONTH(Appt_date__c)=:month AND branch__c =: m_param AND Doctor__c=:y_param]; blockedappts = [select id,appt_date__c,Calander_Day__c,Appt_remarks__c,Block_the_Entire_Day__c from Appointment__c where Block_the_Entire_Day__c=TRUE AND Recordtypeid=:'01290000000YnZw' AND CALENDAR_YEAR(Appt_date__c) =:Year AND CALENDAR_MONTH(Appt_date__c)=:Monthc AND branch__c =: m_param AND Doctor__c=:y_param]; } }
this is the test case i havew written and the error is saying the constructor is not defined
@isTest
private class Remarkscontroller_TC
{
static testmethod void TestController()
{
Remarkscontroller rc= new Remarkscontroller();
}
}
I have made some changes inside your code. Now use the below code for your test coverage.
Public class Remarkscontroller
{
public Appointment__c[] blockedappts {get; set;}
String m_param;
String y_param;
Date Di = system.today();
Public Integer monthc {get;set;}
public Integer Year{get; set;}
Public string monthname {get;set;}
public Remarkscontroller() //Dev_Appt_Calendar_Repeat controller
{
m_param = System.currentPageReference().getParameters().get('br');
y_param = System.currentPageReference().getParameters().get('dr');
Monthc = di.month();
Year= di.year();
show();
}
public void show()
{
if(Monthc == 12){
monthname = 'December';
}
if(Monthc == 11){
monthname = 'November';
}
if(Monthc == 10){
monthname = 'October';
}
if(Monthc == 9){
monthname = 'September';
}
if(Monthc == 8){
monthname = 'August';
}
if(Monthc == 7){
monthname = 'July';
}
if(Monthc == 6){
monthname = 'June';
}
if(Monthc == 5){
monthname = 'May';
}
if(Monthc == 4){
monthname = 'April';
}
if(Monthc == 3){
monthname = 'March';
}
if(Monthc == 2){
monthname = 'Febuary';
}
if(Monthc == 1){
monthname = 'January';
}
blockedappts = [select id,appt_date__c,Calander_Day__c,Appt_remarks__c,Block_the_Entire_Day__c from Appointment__c where Block_the_Entire_Day__c=TRUE AND Recordtypeid=:'01290000000YnZw' AND CALENDAR_YEAR(Appt_date__c) =:Year AND CALENDAR_MONTH(Appt_date__c)=:month AND branch__c =: m_param AND Doctor__c=:y_param];
blockedappts = [select id,appt_date__c,Calander_Day__c,Appt_remarks__c,Block_the_Entire_Day__c from Appointment__c where Block_the_Entire_Day__c=TRUE AND Recordtypeid=:'01290000000YnZw' AND CALENDAR_YEAR(Appt_date__c) =:Year AND CALENDAR_MONTH(Appt_date__c)=:Monthc AND branch__c =: m_param AND Doctor__c=:y_param];
}
static testmethod void TestController()
{
Remarkscontroller rc= new Remarkscontroller();
for(integer i=12; i>0; i--)
{
rc.Monthc--;
rc.show();
}
}
}
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
hi navatar actually when i am trying to save your code i am getiing an error month does not exist at line 60 column 261 so plz check it and give me a solution or let me know wheter we can write a test case for my old code
Hi,
Try below code with 100% coverage
Public class Remarkscontroller {
//public Appointment__c[] blockedappts {get; set;}
String m_param;
String y_param;
Date Di = system.today();
Public Integer monthc {get;set;}
public Integer Year{get; set;}
Public string monthname {get;set;}
//Dev_Appt_Calendar_Repeat controller
public Remarkscontroller()
{
m_param = System.currentPageReference().getParameters().get('br');
y_param = System.currentPageReference().getParameters().get('dr');
Monthc = di.month();
Year= di.year();
show();
}
public void show()
{
if(Monthc == 12){
monthname = 'December';
}
if(Monthc == 11){
monthname = 'November';
}
if(Monthc == 10){
monthname = 'October';
}
if(Monthc == 9){
monthname = 'September';
}
if(Monthc == 8){
monthname = 'August';
}
if(Monthc == 7){
monthname = 'July';
}
if(Monthc == 6){
monthname = 'June';
}
if(Monthc == 5){
monthname = 'May';
}
if(Monthc == 4){
monthname = 'April';
}
if(Monthc == 3){
monthname = 'March';
}
if(Monthc == 2){
monthname = 'Febuary';
}
if(Monthc == 1){
monthname = 'January';
}
//blockedappts = [select id,appt_date__c,Calander_Day__c,Appt_remarks__c,Block_the_Entire_Day__c from Appointment__c where Block_the_Entire_Day__c=TRUE AND Recordtypeid=:'01290000000YnZw' AND CALENDAR_YEAR(Appt_date__c) =:Year AND CALENDAR_MONTH(Appt_date__c)=:month AND branch__c =: m_param AND Doctor__c=:y_param];
//blockedappts = [select id,appt_date__c,Calander_Day__c,Appt_remarks__c,Block_the_Entire_Day__c from Appointment__c where Block_the_Entire_Day__c=TRUE AND Recordtypeid=:'01290000000YnZw' AND CALENDAR_YEAR(Appt_date__c) =:Year AND CALENDAR_MONTH(Appt_date__c)=:Monthc AND branch__c =: m_param AND Doctor__c=:y_param];
}
static testmethod void TestController()
{
Remarkscontroller rc= new Remarkscontroller();
for(integer i=12; i>0; i--)
{
rc.Monthc--;
rc.show();
}
}
}
and also check your soql query
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
hi navatar
i cant hide the query in my controller as it is important to filter some records but if i unhide it i am getting the error so is there any way we can write a test case for a controllere where the constructor is declared using another controller plz help
Hi,
Use this query in your code
blockedappts = [select id,appt_date__c,Calander_Day__c,Appt_remarks__c,Block_the_Entire_Day__c from Appointment__c where Block_the_Entire_Day__c=TRUE AND Recordtypeid=:'01290000000YnZw' AND CALENDAR_YEAR(Appt_date__c) =:Year AND CALENDAR_MONTH(Appt_date__c)=:Monthc AND branch__c =: m_param AND Doctor__c=:y_param];