+ Start a Discussion
abinayaabinaya 

test class for inner class

Hi,

I need to write test class for inner class coverage. 

Class:

public class PerformanceReport
{
public String strFromDate {get; set;}
public String strToDate {get; set;}
public List<PerformanceReportClass> LstPerformanceReportClass {get;set;}
public Class PerformanceReportClass
{
public String strMRName{get;set;}
public String strMonth1{get;set;}
public String strMonth2{get;set;}
public String strMonth3{get;set;}
public String strMonth4{get;set;}
public String strMonth5{get;set;}
public String strMonth6{get;set;}
public String strMonth7{get;set;}
public String strMonth8{get;set;}
public String strMonth9{get;set;}
public String strMonth10{get;set;}
public String strMonth11{get;set;}
public String strMonth12{get;set;}
public List<ReqmtDetailsClass> lstReqmtDetailsClass1{get; set;}
public List<ReqmtDetailsClass> lstReqmtDetailsClass2{get; set;}
public List<ReqmtDetailsClass> lstReqmtDetailsClass3{get; set;}
public List<ReqmtDetailsClass> lstReqmtDetailsClass4{get; set;}
public List<ReqmtDetailsClass> lstReqmtDetailsClass5{get; set;}
public List<ReqmtDetailsClass> lstReqmtDetailsClass6{get; set;}
public List<ReqmtDetailsClass> lstReqmtDetailsClass7{get; set;}
public List<ReqmtDetailsClass> lstReqmtDetailsClass8{get; set;}
public List<ReqmtDetailsClass> lstReqmtDetailsClass9{get; set;}
public List<ReqmtDetailsClass> lstReqmtDetailsClass10{get; set;}
public List<ReqmtDetailsClass> lstReqmtDetailsClass11{get; set;}
public List<ReqmtDetailsClass> lstReqmtDetailsClass12{get; set;}
}
public class ReqmtDetailsClass
{
public string ReqmtName {get; set;}
public string ReqmtStatus {get; set;}
public string ReqmtPostdDate {get; set;}
public string ResumeReqstd {get; set;}
public string ResumeSubmtd {get; set;}
public string ResumeFirstPosted {get; set;}
public string ElapsedTimeFirstResumePosted {get; set;}
public string ReqmtClosedDate {get; set;}
public string ReqmtClosedHrs {get; set;}
public List<CandtDetailsClass> lstCandtdetailClass {get; set;}
public List<CandtDetailsClass> lstCandtdetailClass2 {get; set;}
public List<CandtDetailsClass> lstCandtdetailClass3 {get; set;}
public List<CandtDetailsClass> lstCandtdetailClass4 {get; set;}
public List<CandtDetailsClass> lstCandtdetailClass5 {get; set;}
public List<CandtDetailsClass> lstCandtdetailClass6 {get; set;}
public List<CandtDetailsClass> lstCandtdetailClass7 {get; set;}
public List<CandtDetailsClass> lstCandtdetailClass8 {get; set;}
public List<CandtDetailsClass> lstCandtdetailClass9 {get; set;}
public List<CandtDetailsClass> lstCandtdetailClass10 {get; set;}
public List<CandtDetailsClass> lstCandtdetailClass11 {get; set;}
public List<CandtDetailsClass> lstCandtdetailClass12 {get; set;}
}

public class CandtDetailsClass
{
public string CandtName{get; set;}
public string CandtEmail{get; set;}
}
public PageReference GetReportDetails()
{
List<User> lstAllUser = new List<User>([SELECT id, name, LastModifiedDate, isActive from user where userroleid in (select id from userrole where name='Management Representative')]);
List<User> lstUser = new List<User>();
List<RequirementAssignment__c> lstReqmtAssign = new List<RequirementAssignment__c>();
List<RequirementAssignment__c> FilterReqmtAssign ;
List<RequirementAssignment__c> FilterReqmtAssignMonthly ;
List<Requirement__c> lstReqmts = new List<Requirement__c>();
if(strFromDate != null && strToDate != null)
{
DateTime startDT = DateTime.parse(strFromDate);
system.debug('Date:' + startDT);
DateTime endDT = DateTime.parse(strToDate);
system.debug('Date:' + endDT);
Date NewStartDate;
Integer startMonth = startDT.monthgmt();
Integer endMonth = endDT.monthgmt();
Integer startYear = startDT.yeargmt();
Integer endYear = endDT.yeargmt();
for(User allUser : lstAllUser)
{
if(allUser.IsActive == true)
{
lstUser.add(allUser);
}
else
{
if(allUser.LastModifiedDate > startDT)
{
lstUser.add(allUser);
}
}
}
lstReqmtAssign = [select Status__c, Requirement__c, Lead_Recruiter__c, Recruiter__c, createddate, createdbyid from RequirementAssignment__c where createddate >: startDT and createddate <: endDT ];

LstPerformanceReportClass = new List<PerformanceReportClass>();
for(User MRUSer : lstUser)
{
FilterReqmtAssign = new List<RequirementAssignment__c>();
for(RequirementAssignment__c ReqmAssign : lstReqmtAssign)
{
if(MRUSer.id == ReqmAssign.createdbyid)
{
FilterReqmtAssign.Add(ReqmAssign);
}
}
PerformanceReportClass objPerformanceReportClass = new PerformanceReportClass();
objPerformanceReportClass.strMonth1 = objPerformanceReportClass.strMonth2 = objPerformanceReportClass.strMonth3 = objPerformanceReportClass.strMonth4 = objPerformanceReportClass.strMonth5 = objPerformanceReportClass.strMonth6 = objPerformanceReportClass.strMonth7 = objPerformanceReportClass.strMonth8 = objPerformanceReportClass.strMonth9 = objPerformanceReportClass.strMonth10 = objPerformanceReportClass.strMonth11 = objPerformanceReportClass.strMonth12 = string.valueOf(0);
Integer count = 0;
NewStartDate = startDT.date();
Integer incrMonth = NewStartDate.month();
objPerformanceReportClass.strMRName = MRUSer.name;
if(FilterReqmtAssign != null)
{
for(integer i=startMonth; i<=endMonth; i++)
{
FilterReqmtAssignMonthly = new List<RequirementAssignment__c>();
for(RequirementAssignment__c ReqmAssignUser : FilterReqmtAssign)
{
DateTime ReqmtAssignDt = ReqmAssignUser.createddate;
Date ReqmAssignDate = Date.NewInstance(ReqmtAssignDt.yeargmt(), ReqmtAssignDt.monthgmt(), ReqmtAssignDt.daygmt());
System.Debug('Reqmt Assign Date:' +ReqmAssignDate);
System.Debug('Original Date:' + NewStartDate.month());
if((ReqmAssignDate.month() == incrMonth) && (ReqmAssignDate.year() == NewStartDate.year()))
{
FilterReqmtAssignMonthly.Add(ReqmAssignUser);
}
}
incrMonth++;
System.Debug('List Size:' +FilterReqmtAssignMonthly.size());
if(i==1)
{
objPerformanceReportClass.strMonth1 = string.valueOf(FilterReqmtAssignMonthly.size());
System.Debug('objReqmtAssignClass.strDate1:' +objPerformanceReportClass.strMonth1);
objPerformanceReportClass.lstReqmtDetailsClass1 = new List<ReqmtDetailsClass>();
Set<ID> setReqId = new Set<ID>();
for(RequirementAssignment__c Reqmt : FilterReqmtAssignMonthly)
{
System.Debug('Filter List Monthly'+FilterReqmtAssignMonthly);
System.Debug('Monthly Reqmt' +Reqmt);
setReqId.add(Reqmt.Requirement__c);
}
System.Debug('Id Set:' +setReqId);
if(setReqId.size()>0)
{
for(ID ReqID : setReqId)
{
System.Debug('Reqmt Id:' + ReqID);
List<Requirement__c> lstReqmtsResume= [Select id, Name, Status__c, createddate, No_Of_Resumes__c, Resumes_Submitted__c, Assign_Candidate_date__c, First_Response__c, Req_Closed_Date__c, Req_Closed_hrs__c from Requirement__c where id =:ReqID];
System.Debug('list Reqmts Resume:' +lstReqmtsResume);
List<Candidate_Mapping__c> lstCandtMapping = [select Candidate__r.Candidate_Full_Name__c , Candidate__r.Email__c from Candidate_Mapping__c where Requirement__c =:ReqID];
System.Debug('Candidates List:' +lstCandtMapping);
if(lstReqmtsResume.size()>0)
{
for(Requirement__c req:lstReqmtsResume)
{
ReqmtDetailsClass objReqmtDetailsClass1 = new ReqmtDetailsClass();
objReqmtDetailsClass1.lstCandtdetailClass = new List<CandtDetailsClass>();
System.Debug('Reqmt Resume:' +req);
objReqmtDetailsClass1.ReqmtName = string.valueOf(req.Name);
objReqmtDetailsClass1.ReqmtStatus = string.valueOf(req.Status__c);
objReqmtDetailsClass1.ReqmtPostdDate = string.valueOf(req.createddate);
objReqmtDetailsClass1.ResumeReqstd = string.valueOf(req.No_Of_Resumes__c);
objReqmtDetailsClass1.ResumeSubmtd = string.valueOf(req.Resumes_Submitted__c);
objReqmtDetailsClass1.ResumeFirstPosted = string.valueOf(req.Assign_Candidate_date__c);
objReqmtDetailsClass1.ElapsedTimeFirstResumePosted = string.valueOf(req.First_Response__c);
objReqmtDetailsClass1.ReqmtClosedDate = string.valueOf(req.Req_Closed_Date__c);
objReqmtDetailsClass1.ReqmtClosedHrs = string.valueOf(req.Req_Closed_hrs__c);
System.Debug('objReqmtDetailsClass1:'+objReqmtDetailsClass1);
objPerformanceReportClass.lstReqmtDetailsClass1.add(objReqmtDetailsClass1);
for(Candidate_Mapping__c candt :lstCandtMapping)
{
CandtDetailsClass objCandtDetailsClass1 = new CandtDetailsClass();
objCandtDetailsClass1.CandtName = string.valueOf(candt.Candidate__r.Candidate_Full_Name__c);
objCandtDetailsClass1.CandtEmail = string.valueOf(candt.Candidate__r.Email__c);
objReqmtDetailsClass1.lstCandtdetailClass.add(objCandtDetailsClass1);
}
}
}
}
}

}
else if(i==2)
{
objPerformanceReportClass.strMonth2 = string.valueOf(FilterReqmtAssignMonthly.size());
System.Debug('objReqmtAssignClass.strDate2:' +objPerformanceReportClass.strMonth2);
objPerformanceReportClass.lstReqmtDetailsClass2 = new List<ReqmtDetailsClass>();
Set<ID> setReqId = new Set<ID>();
for(RequirementAssignment__c Reqmt : FilterReqmtAssignMonthly)
{
System.Debug('Filter List Monthly'+FilterReqmtAssignMonthly);
System.Debug('Monthly Reqmt' +Reqmt);
setReqId.add(Reqmt.Requirement__c);
}
System.Debug('Id Set:' +setReqId);
if(setReqId.size()>0)
{
for(ID ReqID : setReqId)
{
System.Debug('Reqmt Id:' + ReqID);
List<Requirement__c> lstReqmtsResume= [Select id, Name, Status__c, createddate, No_Of_Resumes__c, Resumes_Submitted__c, Assign_Candidate_date__c, First_Response__c, Req_Closed_Date__c, Req_Closed_hrs__c from Requirement__c where id =:ReqID];
System.Debug('list Reqmts Resume:' +lstReqmtsResume);
if(lstReqmtsResume.size()>0)
{
for(Requirement__c req:lstReqmtsResume)
{
ReqmtDetailsClass objReqmtDetailsClass2 = new ReqmtDetailsClass();
System.Debug('Reqmt Resume:' +req);
objReqmtDetailsClass2.ReqmtName = string.valueOf(req.Name);
objReqmtDetailsClass2.ReqmtStatus = string.valueOf(req.Status__c);
objReqmtDetailsClass2.ReqmtPostdDate = string.valueOf(req.createddate);
objReqmtDetailsClass2.ResumeReqstd = string.valueOf(req.No_Of_Resumes__c);
objReqmtDetailsClass2.ResumeSubmtd = string.valueOf(req.Resumes_Submitted__c);
objReqmtDetailsClass2.ResumeFirstPosted = string.valueOf(req.Assign_Candidate_date__c);
objReqmtDetailsClass2.ElapsedTimeFirstResumePosted = string.valueOf(req.First_Response__c);
objReqmtDetailsClass2.ReqmtClosedDate = string.valueOf(req.Req_Closed_Date__c);
objReqmtDetailsClass2.ReqmtClosedHrs = string.valueOf(req.Req_Closed_hrs__c);
System.Debug('objReqmtDetailsClass2:'+objReqmtDetailsClass2);
objPerformanceReportClass.lstReqmtDetailsClass2.add(objReqmtDetailsClass2);
}}}}}}
LstPerformanceReportClass.add(objPerformanceReportClass);
}}}
return null;
}}

Test Class:

@isTest
private class testclassperformancereport
{
static testmethod void myTestclass()
{
Candidate_Mapping__c cm = new Candidate_Mapping__c();

Candidate__c cc1=new Candidate__c();
cc1.Name='test';
cc1.Last_name__c='testonek';
cc1.Current_city__c='chennai';
cc1.Current_state__c='Maine';
cc1.Gender__c='Male';
cc1.Employer_Name__c='ttt';
cc1.Email__c='test@gmail.com';
cc1.interview_contact_phone__c='Mobile Phone';
cc1.Contract_type__c='Corp to Corp';
cc1.visa_type__c='H1 B';
cc1.cost__c =100;
cc1.mobile_phone_no__c='9890043500';
cc1.employer_contact_email__c='test@gmail.com';
cc1.Employer_Contact_Name_Name__c='tt';
cc1.Employer_Mobile_No__c='9988009876';
cc1.Employer_Name__c = 'jos';
cc1.Employer_Work_Phone_No__c = '(425) 264-6771';
cc1.Followup_Date__c =date.today();

System.test.startTest();
insert cc1;

cm.Candidate__c=cc1.id;
system.debug('candid:'+cc1.id);

Requirement__c rc1=new Requirement__c();

rc1.Name='SampathReq';
rc1.Job_Title__c='.net';
rc1.Duration__c='6';
rc1.No_Of_Resumes__c=2;
rc1.Min_Cost__c=100;
rc1.Max_Cost__c=200;
rc1.Rate__c=200;
rc1.Rate_Basis__c='Hourly';
rc1.Status__c='open';
rc1.Position_Type__c='Contract';
rc1.State__c='CA';
rc1.City__c='CA';
rc1.Est_Start_Date__c=date.today();
insert rc1;
User lruser = [select u.id from user u where (u.Profile.Name ='Lead Recruiter' or u.Profile.Name ='LR Chatter Only User') and u.ManagerId!=null and u.IsActive= True limit 1] ;
User ruser = [select u.id from user u where (u.Profile.Name ='Recruiter' or u.Profile.Name ='R Chatter Only User') and u.ManagerId!=null and u.IsActive= True limit 1] ;

RequirementAssignment__c reqas = new RequirementAssignment__c();

reqas.Requirement__c = rc1.id;
reqas.AssignStatus__c= 'true';
reqas.Won__c= 'no';
reqas.Lead_Recruiter__c = lruser.id;
//reqas.Recruiter__c = ruser.id;
insert reqas;

cm.Requirement__c=rc1.id;
system.debug('candid:'+cc1.id);

cm.Employer_s_Authorization__c = 'test';
cm.status1__c = 'Applied';
cm.LR_Comments__c = 'test by lr';
cm.MR_Comments__c = 'test by MR';
cm.Requirement_Owner_Email__c = 'testOwner@preludesys.com';
cm.Manager_Email_ID__c = 'testOwner1@preludesys.com';
cm.LR_Status__c = 'Approved';
cm.MR_Status__c = 'Approved';
cm.LR_Status_Date__c = string.valueOf(date.today());
cm.Submitted_to_Client__c = 'Yes';
cm.Interview_Scheduled__c = 'Yes';
cm.Interview_Accepted__c = 'Yes';
cm.Client_Interviewed__c = 'Yes';
cm.Client_Offered__c = 'Yes';
cm.Comments__c = '';
cm.MR_Status1__c = 'Approved' ;

User user = [Select Id from User limit 1] ;

EmailTemplate et = [Select Id, Subject, HtmlValue, Body from EmailTemplate where Name = 'Candidate Approval Email with link EZRE'];
List<ContentVersion> contentList = new List<ContentVersion>();

ContentWorkspace library = [SELECT id FROM ContentWorkspace LIMIT 1];
System.Debug('library.id:'+ library.id);

ContentVersion contentVersionObj = new ContentVersion();

contentVersionObj.title = 'Google';//contentVersionObj.Enablement_Area__c = 'Acct Mgmt';
contentVersionObj.FirstPublishLocationId = library.id;
contentVersionObj.Candidate_Id__c = cc1.Id;
contentVersionObj.VersionData = Blob.valueOf('Ayangar') ;
contentVersionObj.PathOnclient = 'http://www.google.com';
contentVersionObj.Title ='Management Approach';

insert contentVersionObj;
System.Debug('ContentVersionObj:'+ contentVersionObj);

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
efa.setFileName('Sasikumar.Word');
efa.setBody(Blob.ValueOf(et.Body));
System.Debug('efa:' +efa);
String[] toAddresses = new string[]{'dummy@yahoo.com'};
mail.setTargetObjectId(user.Id);
mail.setToAddresses(toAddresses);

mail.setTemplateId(et.Id);

mail.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});
mail.saveAsActivity = false;
// Sends the email
Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});

insert cm;

datetime nowdate = datetime.now();

string strfromdate = nowdate.format('MM/dd/yyyy hh:mm a');

datetime newdate= nowdate.addMonths(2);

string strtodate = newdate.format('MM/dd/yyyy hh:mm a');

List<RequirementAssignment__c> lstReqmtAssign = new List<RequirementAssignment__c>();

PerformanceReport pr = new PerformanceReport();

list<PerformanceReportClass> c = new List<PerformanceReportClass>();

datetime startdate = datetime.parse(strfromdate);
system.debug('startdate :' + startdate);

datetime enddate = datetime.parse(strtodate);
system.debug('enddate :' + enddate);

lstReqmtAssign = [select Status__c, Requirement__c, Lead_Recruiter__c, Recruiter__c, createddate, createdbyid from RequirementAssignment__c where createddate >= 2013-09-01T00:00:00.000+0000 and createddate <=2013-09-25T00:00:00.000+0000 ];

System.debug('lstReqmtAssign: ' + lstReqmtAssign);


List<Requirement__c> lstReqmtsResume= [Select id, Name, Status__c, createddate, No_Of_Resumes__c, Resumes_Submitted__c, Assign_Candidate_date__c, First_Response__c, Req_Closed_Date__c, Req_Closed_hrs__c from Requirement__c where id =:rc1.id];
System.Debug('list Reqmts Resume:' +lstReqmtsResume);

List<Candidate_Mapping__c> lstCandtMapping = [select Candidate__r.Candidate_Full_Name__c , Candidate__r.Email__c from Candidate_Mapping__c where Requirement__c =:rc1.id];
System.Debug('Candidates List:' +lstCandtMapping);

pr.GetReportDetails();

}
}

 

What ever i modify in the test class, the code coverage is 3% only, Kindly help meto fix this.

 

Regards,

Abinaya.

Abhi_TripathiAbhi_Tripathi

Hi abinaya,

 

Wherever you have call that inner class, its code covereage gonna be covered same like Wrapper classes codes get covered,

 

But if not you can call them like

 

MainClass.InnerClass innerController = new MainClass.InnerClass();

 

You can check this blog for your help

http://abhithetechknight.blogspot.in/2013/10/salesforce-test-class-basics.html

abinayaabinaya
as u mentioned i have called the inner class but the method is not covering.

plz find the test class

@isTest(seealldata = true)
private class testclassperformancereport
{
static testmethod void myTestclass()
{

datetime nowdate = datetime.now();

string strfromdate = nowdate.format('MM/dd/yyyy hh:mm a');

datetime newdate= nowdate.addMonths(2);

string strtodate = newdate.format('MM/dd/yyyy hh:mm a');

List<RequirementAssignment__c> lstReqmtAssign = new List<RequirementAssignment__c>();

PerformanceReport pr = new PerformanceReport();

PerformanceReport.PerformanceReportClass prc = new PerformanceReport.PerformanceReportClass();

PerformanceReport.ReqmtDetailsClass rdc = new PerformanceReport.ReqmtDetailsClass();

list<PerformanceReportClass> c = new List<PerformanceReportClass>();

datetime startdate = datetime.parse(strfromdate);
system.debug('startdate :' + startdate);

datetime enddate = datetime.parse(strtodate);
system.debug('enddate :' + enddate);

lstReqmtAssign = [select Status__c, Requirement__c, Lead_Recruiter__c, Recruiter__c, createddate, createdbyid from RequirementAssignment__c where createddate >= 2013-09-01T00:00:00.000+0000 and createddate <=2013-09-25T00:00:00.000+0000 ];

System.debug('lstReqmtAssign: ' + lstReqmtAssign);


List<Requirement__c> lstReqmtsResume= [Select id, Name, Status__c, createddate, No_Of_Resumes__c, Resumes_Submitted__c, Assign_Candidate_date__c, First_Response__c, Req_Closed_Date__c, Req_Closed_hrs__c from Requirement__c];
System.Debug('list Reqmts Resume:' +lstReqmtsResume);

List<Candidate_Mapping__c> lstCandtMapping = [select Candidate__r.Candidate_Full_Name__c , Candidate__r.Email__c from Candidate_Mapping__c];
System.Debug('Candidates List:' +lstCandtMapping);

pr.GetReportDetails();

}
}
Abhi_TripathiAbhi_Tripathi

Dont query on that Object  RequirementAssignment__c , Requirement__c, Candidate_Mapping__c create there test  records with certain field values as ou want in the method and them try that,

 

if you are calling that method, then it will definetly gonna pass in test class, and code will get covered.

abinayaabinaya

hi abhi,

 

I have tried as you mentioned in the above comment.

 

Now also it is covering only 15%

 

@isTest 
private class testclassperformancereport
{
   static testmethod void myTestclass()
   {
      
      datetime nowdate = datetime.now();
      
      string strfromdate = nowdate.format('MM/dd/yyyy hh:mm a');   
      
      datetime newdate= nowdate.addMonths(2);
      
      string strtodate = newdate.format('MM/dd/yyyy hh:mm a');
      
      List<RequirementAssignment__c> lstReqmtAssign = new List<RequirementAssignment__c>();
      
      PerformanceReport pr = new PerformanceReport();
      
      PerformanceReport.PerformanceReportClass prc = new PerformanceReport.PerformanceReportClass();
      
      PerformanceReport.ReqmtDetailsClass rdc = new PerformanceReport.ReqmtDetailsClass();
     
      list<PerformanceReportClass> c = new List<PerformanceReportClass>();
    
      Candidate_Mapping__c cm = new Candidate_Mapping__c();

      Candidate__c cc1=new Candidate__c();
                        
      cc1.Name='test';
      cc1.Last_name__c='testonek';
      cc1.Current_city__c='chennai';
      cc1.Current_state__c='Maine';
      cc1.Gender__c='Male';
      cc1.Employer_Name__c='ttt';
      cc1.Email__c='test@gmail.com';
      cc1.interview_contact_phone__c='Mobile Phone';
      cc1.Contract_type__c='Corp to Corp';
      cc1.visa_type__c='H1 B';
      cc1.cost__c =100;
      cc1.mobile_phone_no__c='9890043500';
      cc1.employer_contact_email__c='test@gmail.com';
      cc1.Employer_Contact_Name_Name__c='tt';
      cc1.Employer_Mobile_No__c='9988009876';       
      cc1.Employer_Name__c = 'jos'; 
      cc1.Employer_Work_Phone_No__c = '(425) 264-6771';              
      cc1.Followup_Date__c =date.today();              
      
      System.test.startTest();
      insert cc1;          
                
      cm.Candidate__c=cc1.id;
      system.debug('candid:'+cc1.id);
      
      Requirement__c rc1=new Requirement__c();
            
      rc1.Name='SampathReq';
      rc1.Job_Title__c='.net';      
      rc1.Duration__c='6';
      rc1.No_Of_Resumes__c=2;
      rc1.Min_Cost__c=100;
      rc1.Max_Cost__c=200;
      rc1.Rate__c=200;
      rc1.Rate_Basis__c='Hourly';
      rc1.Status__c='open';
      rc1.Position_Type__c='Contract';
      rc1.State__c='CA';
      rc1.City__c='CA';
      rc1.Est_Start_Date__c=date.today(); 
                
      insert rc1;
                
      User lruser = [select u.id from user u where (u.Profile.Name ='Lead Recruiter' or u.Profile.Name ='LR Chatter Only User') and u.ManagerId!=null and u.IsActive= True limit 1] ; 
      User ruser = [select u.id from user u where (u.Profile.Name ='Recruiter' or u.Profile.Name ='R Chatter Only User') and u.ManagerId!=null and u.IsActive= True limit 1] ; 
      
      RequirementAssignment__c reqas = new RequirementAssignment__c();
        
      reqas.Requirement__c = rc1.id;
      reqas.AssignStatus__c= 'true';
      reqas.Won__c= 'no';
      reqas.Lead_Recruiter__c = lruser.id;
                //reqas.Recruiter__c = ruser.id;      
      insert reqas;
                
      cm.Requirement__c=rc1.id;
      system.debug('candid:'+cc1.id);  

      cm.Employer_s_Authorization__c = 'test';
      cm.status1__c = 'Applied';  
      cm.LR_Comments__c = 'test by lr';
      cm.MR_Comments__c = 'test by MR'; 
      cm.Requirement_Owner_Email__c = 'testOwner@preludesys.com';
      cm.Manager_Email_ID__c = 'testOwner1@preludesys.com';
      cm.LR_Status__c = 'Approved'; 
      cm.MR_Status__c = 'Approved'; 
      cm.LR_Status_Date__c = string.valueOf(date.today());              
      cm.Submitted_to_Client__c = 'Yes'; 
      cm.Interview_Scheduled__c = 'Yes'; 
      cm.Interview_Accepted__c = 'Yes'; 
      cm.Client_Interviewed__c = 'Yes'; 
      cm.Client_Offered__c = 'Yes'; 
      cm.Comments__c = '';  
      cm.MR_Status1__c = 'Approved' ;

      User user = [Select Id from User limit 1] ; 
             
      EmailTemplate et = [Select Id, Subject, HtmlValue, Body from EmailTemplate where Name = 'Candidate Approval Email with link EZRE'];            
      List<ContentVersion> contentList = new List<ContentVersion>();
           
      ContentWorkspace library = [SELECT id FROM ContentWorkspace LIMIT 1];
      System.Debug('library.id:'+ library.id);    

      ContentVersion contentVersionObj = new ContentVersion();          
  
      contentVersionObj.title = 'Google';//contentVersionObj.Enablement_Area__c = 'Acct Mgmt';       
      contentVersionObj.FirstPublishLocationId = library.id;       
      contentVersionObj.Candidate_Id__c = cc1.Id; 
      contentVersionObj.VersionData = Blob.valueOf('Ayangar') ; 
      contentVersionObj.PathOnclient = 'http://www.google.com';
      contentVersionObj.Title ='Management Approach';  
           
      insert contentVersionObj;     
      System.Debug('ContentVersionObj:'+ contentVersionObj);
           
      Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
      Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
      efa.setFileName('Sasikumar.Word');
      efa.setBody(Blob.ValueOf(et.Body));    
      System.Debug('efa:' +efa);    
      String[] toAddresses = new string[]{'dummy@yahoo.com'};
      mail.setTargetObjectId(user.Id);
      mail.setToAddresses(toAddresses);            
    
      mail.setTemplateId(et.Id);          
         
      mail.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});
      mail.saveAsActivity = false;
      // Sends the email
      Messaging.SendEmailResult [] r =  Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail}); 
                        
      insert cm; 
      
      
      pr.GetReportDetails();
     
   }
}

Abhi_TripathiAbhi_Tripathi

perfect, now go to developer console and check which line is not covered, and go for that line , and try to create that condition which will cover that line.

 

Mark solution as correct, with kudos for others, if it helped you

abinayaabinaya

only 60 lines is covering in that class. totally there is 366 lines in that class. 

 

the bold lines are covered but after that the code coverage is not working.

 

 

  public PageReference GetReportDetails()
    {
        List<User> lstAllUser = new List<User>([SELECT id, name, LastModifiedDate, isActive from user where userroleid in (select id from userrole where name='Management Representative')]);
        List<User> lstUser = new List<User>();
        
        List<RequirementAssignment__c> lstReqmtAssign = new List<RequirementAssignment__c>();
        
        List<RequirementAssignment__c> FilterReqmtAssign ;
        
        List<RequirementAssignment__c> FilterReqmtAssignMonthly ;
        
        List<Requirement__c> lstReqmts = new List<Requirement__c>();
        
        
        if(strFromDate != null && strToDate != null)
        {
        
        DateTime startDT = DateTime.parse(strFromDate);
        system.debug('Date:' + startDT);
                
        DateTime endDT = DateTime.parse(strToDate);
        system.debug('Date:' + endDT);
        
        Date NewStartDate;
              
        Integer startMonth = startDT.monthgmt();
        Integer endMonth = endDT.monthgmt();
        Integer startYear = startDT.yeargmt();
        Integer endYear = endDT.yeargmt();
          
        for(User allUser : lstAllUser)
        {
            if(allUser.IsActive == true)
            {
                lstUser.add(allUser);
            }
            else
            {
                if(allUser.LastModifiedDate > startDT)
                {
                    lstUser.add(allUser);
                }
            }
        }
        
        
       lstReqmtAssign = [select Status__c, Requirement__c, Lead_Recruiter__c, Recruiter__c,  createddate, createdbyid from RequirementAssignment__c where createddate >: startDT and createddate <: endDT ];

       LstPerformanceReportClass = new List<PerformanceReportClass>();
       
       for(User MRUSer : lstUser)
       {
           FilterReqmtAssign = new List<RequirementAssignment__c>();  
           for(RequirementAssignment__c ReqmAssign : lstReqmtAssign)
           {
               if(MRUSer.id == ReqmAssign.createdbyid)
               {
                   FilterReqmtAssign.Add(ReqmAssign);                    
               }
           }
           PerformanceReportClass objPerformanceReportClass = new PerformanceReportClass();
           objPerformanceReportClass.strMonth1 = objPerformanceReportClass.strMonth2 = objPerformanceReportClass.strMonth3 = objPerformanceReportClass.strMonth4 = objPerformanceReportClass.strMonth5 = objPerformanceReportClass.strMonth6 = objPerformanceReportClass.strMonth7 = objPerformanceReportClass.strMonth8 = objPerformanceReportClass.strMonth9 = objPerformanceReportClass.strMonth10 = objPerformanceReportClass.strMonth11 = objPerformanceReportClass.strMonth12 = string.valueOf(0);
           
           Integer count = 0;
           NewStartDate = startDT.date(); 
           Integer incrMonth = NewStartDate.month();
           
           objPerformanceReportClass.strMRName = MRUSer.name;
           
           if(FilterReqmtAssign != null)
           {
               for(integer i=startMonth; i<=endMonth; i++)
               {
                   FilterReqmtAssignMonthly = new List<RequirementAssignment__c>();
                   
                   for(RequirementAssignment__c  ReqmAssignUser : FilterReqmtAssign)
                   {                     
                       DateTime ReqmtAssignDt = ReqmAssignUser.createddate;
                       Date ReqmAssignDate = Date.NewInstance(ReqmtAssignDt.yeargmt(), ReqmtAssignDt.monthgmt(), ReqmtAssignDt.daygmt());
                       
                       System.Debug('Reqmt Assign Date:' +ReqmAssignDate);
                       System.Debug('Original Date:' + NewStartDate.month());
                       
                       if((ReqmAssignDate.month() == incrMonth) && (ReqmAssignDate.year() == NewStartDate.year()))
                       {
                           FilterReqmtAssignMonthly.Add(ReqmAssignUser);
                           
                       }
                   }
                       incrMonth++;
                       System.Debug('List Size:' +FilterReqmtAssignMonthly.size());
 
                
                       if(i==1)
                       {                           
                           objPerformanceReportClass.strMonth1 = string.valueOf(FilterReqmtAssignMonthly.size());
                           System.Debug('objReqmtAssignClass.strDate1:' +objPerformanceReportClass.strMonth1);
                           
                            objPerformanceReportClass.lstReqmtDetailsClass1 = new List<ReqmtDetailsClass>();
                            
                            Set<ID> setReqId = new Set<ID>();
                            for(RequirementAssignment__c Reqmt : FilterReqmtAssignMonthly)
                            {
                                System.Debug('Filter List Monthly'+FilterReqmtAssignMonthly);
                                System.Debug('Monthly Reqmt' +Reqmt);
                                setReqId.add(Reqmt.Requirement__c);                                
                            }
                            System.Debug('Id Set:' +setReqId);
                            if(setReqId.size()>0)
                            {                                
                                for(ID ReqID : setReqId)
                                {                          
                                    System.Debug('Reqmt Id:' + ReqID);          
                                    List<Requirement__c> lstReqmtsResume= [Select id, Name, Status__c, createddate, No_Of_Resumes__c, Resumes_Submitted__c, Assign_Candidate_date__c, First_Response__c, Req_Closed_Date__c, Req_Closed_hrs__c  from Requirement__c where id =:ReqID];
                                    System.Debug('list Reqmts Resume:' +lstReqmtsResume);
                                    
                                    List<Candidate_Mapping__c> lstCandtMapping = [select Candidate__r.Candidate_Full_Name__c , Candidate__r.Email__c from Candidate_Mapping__c where Requirement__c =:ReqID];
                                    System.Debug('Candidates List:' +lstCandtMapping);
                                    
                                    if(lstReqmtsResume.size()>0)
                                    { 
                                        for(Requirement__c req:lstReqmtsResume)
                                        {
                                            ReqmtDetailsClass objReqmtDetailsClass1 = new ReqmtDetailsClass();
                                            objReqmtDetailsClass1.lstCandtdetailClass = new List<CandtDetailsClass>(); 
                                            
                                            System.Debug('Reqmt Resume:' +req);
                                             objReqmtDetailsClass1.ReqmtName = string.valueOf(req.Name);    
                                             objReqmtDetailsClass1.ReqmtStatus = string.valueOf(req.Status__c);
                                             objReqmtDetailsClass1.ReqmtPostdDate = string.valueOf(req.createddate);
                                             objReqmtDetailsClass1.ResumeReqstd = string.valueOf(req.No_Of_Resumes__c);
                                             objReqmtDetailsClass1.ResumeSubmtd = string.valueOf(req.Resumes_Submitted__c);
                                             objReqmtDetailsClass1.ResumeFirstPosted = string.valueOf(req.Assign_Candidate_date__c);
                                             objReqmtDetailsClass1.ElapsedTimeFirstResumePosted = string.valueOf(req.First_Response__c);
                                             objReqmtDetailsClass1.ReqmtClosedDate = string.valueOf(req.Req_Closed_Date__c);
                                             objReqmtDetailsClass1.ReqmtClosedHrs = string.valueOf(req.Req_Closed_hrs__c);
                                             
                                             System.Debug('objReqmtDetailsClass1:'+objReqmtDetailsClass1);
                                             objPerformanceReportClass.lstReqmtDetailsClass1.add(objReqmtDetailsClass1);
                                            
                                             for(Candidate_Mapping__c candt :lstCandtMapping)
                                             {
                                                 CandtDetailsClass objCandtDetailsClass1 = new CandtDetailsClass();
                                                 
                                                 objCandtDetailsClass1.CandtName = string.valueOf(candt.Candidate__r.Candidate_Full_Name__c);
                                                 objCandtDetailsClass1.CandtEmail = string.valueOf(candt.Candidate__r.Email__c);
                                                 objReqmtDetailsClass1.lstCandtdetailClass.add(objCandtDetailsClass1);
                                             }
                                        }
                                    }                                   
                                }
                                
                            }

                       }
                       else if(i==2)
                       {
                           objPerformanceReportClass.strMonth2 = string.valueOf(FilterReqmtAssignMonthly.size());
                           System.Debug('objReqmtAssignClass.strDate2:' +objPerformanceReportClass.strMonth2);
                           
                           objPerformanceReportClass.lstReqmtDetailsClass2 = new List<ReqmtDetailsClass>();                            
                            
                            Set<ID> setReqId = new Set<ID>();
                            for(RequirementAssignment__c Reqmt : FilterReqmtAssignMonthly)
                            {
                                System.Debug('Filter List Monthly'+FilterReqmtAssignMonthly);
                                System.Debug('Monthly Reqmt' +Reqmt);
                                setReqId.add(Reqmt.Requirement__c);                                
                            }
                            System.Debug('Id Set:' +setReqId);
                            if(setReqId.size()>0)
                            {                                
                                for(ID ReqID : setReqId)
                                {                          
                                    System.Debug('Reqmt Id:' + ReqID);          
                                    List<Requirement__c> lstReqmtsResume= [Select id, Name, Status__c, createddate, No_Of_Resumes__c, Resumes_Submitted__c, Assign_Candidate_date__c, First_Response__c, Req_Closed_Date__c, Req_Closed_hrs__c  from Requirement__c where id =:ReqID];
                                    System.Debug('list Reqmts Resume:' +lstReqmtsResume);
                                    if(lstReqmtsResume.size()>0)
                                    { 
                                        for(Requirement__c req:lstReqmtsResume)
                                        {
                                            ReqmtDetailsClass objReqmtDetailsClass2 = new ReqmtDetailsClass();
                                            System.Debug('Reqmt Resume:' +req);
                                             objReqmtDetailsClass2.ReqmtName = string.valueOf(req.Name);    
                                             objReqmtDetailsClass2.ReqmtStatus = string.valueOf(req.Status__c);
                                             objReqmtDetailsClass2.ReqmtPostdDate = string.valueOf(req.createddate);
                                             objReqmtDetailsClass2.ResumeReqstd = string.valueOf(req.No_Of_Resumes__c);
                                             objReqmtDetailsClass2.ResumeSubmtd = string.valueOf(req.Resumes_Submitted__c);
                                             objReqmtDetailsClass2.ResumeFirstPosted = string.valueOf(req.Assign_Candidate_date__c);
                                             objReqmtDetailsClass2.ElapsedTimeFirstResumePosted = string.valueOf(req.First_Response__c);
                                             objReqmtDetailsClass2.ReqmtClosedDate = string.valueOf(req.Req_Closed_Date__c);
                                             objReqmtDetailsClass2.ReqmtClosedHrs = string.valueOf(req.Req_Closed_hrs__c);
                                             
                                             System.Debug('objReqmtDetailsClass2:'+objReqmtDetailsClass2);
                                            objPerformanceReportClass.lstReqmtDetailsClass2.add(objReqmtDetailsClass2);
                                        }
                                    }                                   
                                }
                                
                            }
                       }

SRajesh8SRajesh8

Hi,

 

Please satisfy that if condition i.e

 

pr.strFromDate ='Testing';

pr.strToDate ='Testy';

 

after this call ur methods.

 

Regards,

Rajesh.