You need to sign in to do that
Don't have an account?
HARI KRISHNA
_____________This is the Class where i am facing problem------------------------------
public class SaveMultiObj {
public humanresource__c hr{get;set;}
public CandidateHr__c cand{get;set;}
public AdminService__c admin{get;set;}
public SaveMultiObj(){
hr=new humanresource__c();
cand=new CandidateHr__c();
admin=new AdminService__c ();
}
public void custsave(){
insert hr;
cand.HumanResource__c=hr.id;
cand.rank__c=hr.rank__c;
cand.last_name__c=hr.last_name__c;
insert cand;
}
public void custUpdate() {
CandidateHr__c cand1 =[select id,last_name__c,rank__c,name from candidatehr__c where name=:cand.name];
cand1.last_name__c=hr.last_name__c;
cand1.rank__c=hr.rank__c;
update cand1;
admin.CandidateHr__c=cand1.id;
admin.rank__c=cand1.rank__c;
admin.last_name__c=cand1.last_name__c;
insert admin;
}
}
-------------------------This is Test Class which is related to above Class ---which able to cover only 68%--------
@isTest
public class SaveMultiObj_TC
{
static testMethod void testMthd()
{
SaveMultiObj s=new SaveMultiObj ();
s.custsave();
s.custUpdate();
s.hr=new humanresource__c (name='xxx');
s.cand=new CandidateHr__c (name='yyy');
insert s.cand;
s.cand.name='yyo';
update s.cand;
s.admin=new AdminService__c (name='uuu');
insert s.admin;
}
}
Help me Resolve Code Coverage Problem
_____________This is the Class where i am facing problem------------------------------
public class SaveMultiObj {
public humanresource__c hr{get;set;}
public CandidateHr__c cand{get;set;}
public AdminService__c admin{get;set;}
public SaveMultiObj(){
hr=new humanresource__c();
cand=new CandidateHr__c();
admin=new AdminService__c ();
}
public void custsave(){
insert hr;
cand.HumanResource__c=hr.id;
cand.rank__c=hr.rank__c;
cand.last_name__c=hr.last_name__c;
insert cand;
}
public void custUpdate() {
CandidateHr__c cand1 =[select id,last_name__c,rank__c,name from candidatehr__c where name=:cand.name];
cand1.last_name__c=hr.last_name__c;
cand1.rank__c=hr.rank__c;
update cand1;
admin.CandidateHr__c=cand1.id;
admin.rank__c=cand1.rank__c;
admin.last_name__c=cand1.last_name__c;
insert admin;
}
}
-------------------------This is Test Class which is related to above Class ---which able to cover only 68%--------
@isTest
public class SaveMultiObj_TC
{
static testMethod void testMthd()
{
SaveMultiObj s=new SaveMultiObj ();
s.custsave();
s.custUpdate();
s.hr=new humanresource__c (name='xxx');
s.cand=new CandidateHr__c (name='yyy');
insert s.cand;
s.cand.name='yyo';
update s.cand;
s.admin=new AdminService__c (name='uuu');
insert s.admin;
}
}
HI,
You test class is nothing but unit testing.
Similar to the flow you follow from UI. Thing is you need to create the records before quering etc.
It would be best if you go through this link first.
https://developer.salesforce.com/page/An_Introduction_to_Apex_Code_Test_Methods
Regards,
MCS
===============
Check This..
isTest
public class SaveMultiObj_TC
{
static testMethod void testMthd()
{
SaveMultiObj s=new SaveMultiObj ();
s.custsave();
s.hr=new humanresource__c (name='xxx');
s.cand=new CandidateHr__c (name='yyy');
insert s.cand;
s.cand.name='yyo';
update s.cand;
s.custUpdate();
s.admin=new AdminService__c (name='uuu');
insert s.admin;
}