You need to sign in to do that
Don't have an account?
RAJU_DEEP
test code help
Hello,
I created the controller class with lots of methods. The test code also needed for this class and i written the test code for the various methods which runs fine but I stuck in the creation of test code for this two methods. Here is the Controller code for that particular method.
public String valueOne { get; set; } public String valueTwo { get; set; } public String valueThree { get; set; } Attendance_Detail__c attends; public void saveAttend() { if(attends.SignOut_Time__c != null && attends.SignIn_Time__c < attends.SignOut_Time__c){ List<Attendance_Detail__c> updateAttendance = [select name, SignOut_Time__c, SignIn_Time__c from Attendance_Detail__c where User_Email_Id__c = :attends.User_Email_Id__c and Current_Date__c =: onlyDate]; for(Attendance_Detail__c aDetail : updateAttendance) { if(aDetail.SignIn_Time__c != null && attends.SignIn_Time__c < attends.SignOut_Time__c) { aDetail.SignOut_Time__c = attends.SignOut_Time__c; update aDetail; } } }else{ if(attends.SignIn_Time__c != null){ Attendance_Detail__c attInsert = new Attendance_Detail__c( User_Email_Id__c = attends.User_Email_Id__c, SignIn_Time__c = attends.SignIn_Time__c, SignOut_Time__c = attends.SignOut_Time__c, Current_Date__c = onlyDate ); insert attInsert; } } } public PageReference iWantMyJSValues() { valueOne = Apexpages.currentPage().getParameters().get('one'); valueTwo = Apexpages.currentPage().getParameters().get('two'); valueThree = Apexpages.currentPage().getParameters().get('three'); attends.SignIn_Time__c = [select SignIn_Time__c from Attendance_Detail__c where User_Email_Id__c =: valueOne and Current_Date__c =: onlyDate].SignIn_Time__c; attends.SignOut_Time__c = [select SignOut_Time__c from Attendance_Detail__c where User_Email_Id__c =: valueOne and Current_Date__c =: onlyDate].SignOut_Time__c; return null; }
Is there any help to write the test code for this two.
Thanks in advance.
Raju.
Hi,
For the Pagereference method IWantMyJSValues use the following statement and give value for One, Two, Three etc
ApexPages.currentPage().getParameters().put('One', Value);
initialize Sign inTime__c and Only date
Then simply call the method IwantMyJSValues in your test class.
For the Method saveAttend also initialze the necessary values and call that in the test class.
Its should work fine.
Please find below the testmethod for your code :
@isTest
private class Testclass
{
static testMethod void class_name()
{
Attendance_Detail__c att = new Attendance_Detail__c(SignOut_Time__c = '10',SignIn_Time__c = '8',User_Email_Id__c = 'a@dolby.com',Current_Date__c = system.now());
insert att;
Id vid1 = ApexPages.currentPage().getParameters().put('one',att.Id);
Id vid2 = ApexPages.currentPage().getParameters().put('two',att.Id);
Id vid3 = ApexPages.currentPage().getParameters().put('three',att.Id);
// create a instance of class...
class_name controller = new class_name();
controller.saveAttend();
PageReference pr = controller.iWantMyJSValues();
}
}
Hope this helps.