You need to sign in to do that
Don't have an account?
test case help
thsis i smy controller and i am unable to cover the if condition pz help me resolve the issue
public class timesheetmanagement
{
public String weekselection{get; set;}
public String incselection{get; set;}
Public List<Timesheet_Entry__c> tentries;
Public List<Timesheet_Entry__c> otherentries;
Public Date SelectedWeek;
public Id oppId {get; set;}
Public void deltsheet()
{
String rownumber = System.currentPagereference().getParameters().get('rownumber');
Decimal rownumb = Decimal.Valueof(rownumber);
Integer rowno = rownumb.IntValue();
String tentryid = System.currentPagereference().getParameters().get('tentryid');
system.debug('tentries tentryid'+tentryid);
if (rownumber != '')
tentries.remove(rowno);
}
public void onloadfunction()
{
if ( weekselection != null)
{
SelectedWeek = date.valueOf(weekselection);
system.debug('The Selected Week is'+SelectedWeek);
tentries = [select Id,Project__c,Displayfields__c,Tasks_for_Project__c,Effort__c,Week_Start_Date__c,Mon__c,Tue__c,Wed__c,Thu__c,Fri__c,Sat__c,Sun__c,Project_Task__c from Timesheet_Entry__c where Week_Start_Date__c=:SelectedWeek and Project__c!=NULL and OwnerId=:Userinfo.getUserId()];
otherentries = [select Comments__c,Displayfields__c,Tasks_Other__c,Effort__c,Week_Start_Date__c,Mon__c,Tue__c,Wed__c,Thu__c,Fri__c,Sat__c,Sun__c,Project_Task__c from Timesheet_Entry__c where Week_Start_Date__c=:SelectedWeek and Project__c=NULL and OwnerId=:Userinfo.getUserId()];
}
Hi,
Use the below code in your test class:
I think this will solve your issue.
All Answers
Hi,
Use the below code in your test class:
I think this will solve your issue.
Hi,
Try the blow code with test code as reference:
public class timesheetmanagement
{
public String weekselection{get; set;}
public String incselection{get; set;}
Public List<Timesheet_Entry__c> tentries;
Public List<Timesheet_Entry__c> otherentries;
Public Date SelectedWeek;
public Id oppId {get; set;}
public timesheetmanagement()
{
tentries=new List<Timesheet_Entry__c>();
}
Public void deltsheet()
{
String rownumber = System.currentPagereference().getParameters().get('rownumber');
Decimal rownumb = Decimal.Valueof(rownumber);
Integer rowno = rownumb.IntValue();
String tentryid = System.currentPagereference().getParameters().get('tentryid');
system.debug('tentries tentryid'+tentryid);
if (rownumber != '')
if(tentries.size()>0)
tentries.remove(rowno);
}
public void onloadfunction()
{
if ( weekselection != null)
{
SelectedWeek = date.valueOf(weekselection);
system.debug('The Selected Week is'+SelectedWeek);
tentries = [select Id,Project__c,Displayfields__c,Tasks_for_Project__c,Effort__c,Week_Start_Date__c,Mon__c,Project_Task__c from Timesheet_Entry__c where Week_Start_Date__c=:SelectedWeek and Project__c!=NULL and OwnerId=:Userinfo.getUserId()];
otherentries = [select Comments__c,Displayfields__c,Tasks_Other__c,Effort__c,Week_Start_Date__c,Mon__c,Project_Task__c from Timesheet_Entry__c where Week_Start_Date__c=:SelectedWeek and Project__c=NULL and OwnerId=:Userinfo.getUserId()];
}
}
// Test Method
public static testMethod void CoverConstructor()
{
Timesheet_Entry__c t=new Timesheet_Entry__c(name='dummy1',Week_Start_Date__c=date.valueof('2012-3-12'));
insert t;
Test.setCurrentPage(Page.vf_timesheetmanagement);
ApexPages.currentPage().getParameters().put('rownumber','5');
ApexPages.currentPage().getParameters().put('tentryid','fve');
timesheetmanagement tms=new timesheetmanagement();
tms.weekselection='2012-3-12';
tms.deltsheet();
tms.onloadfunction();
}
}
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
we can write like bellow also. it will worl
Timesheet_Entry__c t=new Timesheet_Entry__c(name='dummy1',Week_Start_Date__
c=date.valueof('2012-3-12'));
insert t;
ApexPages.currentPage().getParameters().put('tentr
yid','fve');
timesheetmanagement tms=new timesheetmanagement();
tms.weekselection= t.Week_Start_Date__c;
tms.deltsheet();
tms.onloadfunction();