You need to sign in to do that
Don't have an account?
Tillu
Please any one correct this below Test Class ?
I have writtened a test class for below class. But this is controller class. I am unable to cover code for page reference method and all. please any one improve this code ?
public with sharing class SFDC_Class_Controller_Final{
public list<SFDC_Enrollment__c> Enrolment { get; set; }
public SFDC_Class__c cls{set;get;}
public SFDC_Class_Controller_Final(ApexPages.StandardController controller) {
this.cls = (SFDC_Class__c)controller.getRecord();
if(this.cls.Id != null){
Enrolment = [select Contact__c, Final_Exam__c, Final_Grade_Value__c, Class__r.Name,Class__r.id from SFDC_Enrollment__c where Class__r.id=:cls.id AND RecordType.Name like '%HLS HFS %'];
}
}
public pagereference save(){
try{
upsert cls;
upsert Enrolment;
Pagereference p = new PageReference('/'+cls.Id);
p.setRedirect(true);
return p;
}
catch(Exception e){}
return null;
}
public pagereference clear(){
for(SFDC_Enrollment__c enro:Enrolment ){
enro.Final_Exam__c=null;
enro.Final_Grade_Value__c=null;
}
return null;
}
}
Here is Test class :
@isTest
public with sharing class SFDC_Class_Controller_Final_Test{
static testMethod void validatestudentdetails(){
SFDC_Enrollment__c sccf=new SFDC_Enrollment__c();
//sccf.Contact__c='kirthika@gmail.com';
sccf.Final_Exam__c=100;
sccf.Final_Grade_Value__c=100;
insert sccf;
SFDC_Class__c scc=new SFDC_Class__c();
scc.name='testclass';
insert scc;
}
}
public with sharing class SFDC_Class_Controller_Final{
public list<SFDC_Enrollment__c> Enrolment { get; set; }
public SFDC_Class__c cls{set;get;}
public SFDC_Class_Controller_Final(ApexPages.StandardController controller) {
this.cls = (SFDC_Class__c)controller.getRecord();
if(this.cls.Id != null){
Enrolment = [select Contact__c, Final_Exam__c, Final_Grade_Value__c, Class__r.Name,Class__r.id from SFDC_Enrollment__c where Class__r.id=:cls.id AND RecordType.Name like '%HLS HFS %'];
}
}
public pagereference save(){
try{
upsert cls;
upsert Enrolment;
Pagereference p = new PageReference('/'+cls.Id);
p.setRedirect(true);
return p;
}
catch(Exception e){}
return null;
}
public pagereference clear(){
for(SFDC_Enrollment__c enro:Enrolment ){
enro.Final_Exam__c=null;
enro.Final_Grade_Value__c=null;
}
return null;
}
}
Here is Test class :
@isTest
public with sharing class SFDC_Class_Controller_Final_Test{
static testMethod void validatestudentdetails(){
SFDC_Enrollment__c sccf=new SFDC_Enrollment__c();
//sccf.Contact__c='kirthika@gmail.com';
sccf.Final_Exam__c=100;
sccf.Final_Grade_Value__c=100;
insert sccf;
SFDC_Class__c scc=new SFDC_Class__c();
scc.name='testclass';
insert scc;
}
}
Then you need to execute some of the methods and confirm that the behaviour is as expected based on your test data.