You need to sign in to do that
Don't have an account?

unable to do code coverage for this below coved my test code is covering 63%
Hi I'M new to salesforce.com. I'm unable to do code coverage for this below coved my test code is covering 63% only what i have learnt from my training class is simply by covering methods in the class we will get 75%
class:
--------
public with sharing class AccFieldsIn2DiffVfToSave_cls {
public PageReference doSave() {
insert objA;
return (new pagereference('/apex/AccFieldsIn2DiffVfToSave2?id='+obja.Id).setredirect(true));
}
public Account objA { get; set; }
public AccFieldsIn2DiffVfToSave_cls(){
objA = new Account();
}
}
test class:
--------------
@isTest
private class AccFieldsIn2DiffVfToSave2_tst{
static testmethod void mytest(){
AccFieldsIn2DiffVfToSave2 obj = new AccFieldsIn2DiffVfToSave2 ();
obj.doSave();
}
}
class:
--------
public with sharing class AccFieldsIn2DiffVfToSave_cls {
public PageReference doSave() {
insert objA;
return (new pagereference('/apex/AccFieldsIn2DiffVfToSave2?id='+obja.Id).setredirect(true));
}
public Account objA { get; set; }
public AccFieldsIn2DiffVfToSave_cls(){
objA = new Account();
}
}
test class:
--------------
@isTest
private class AccFieldsIn2DiffVfToSave2_tst{
static testmethod void mytest(){
AccFieldsIn2DiffVfToSave2 obj = new AccFieldsIn2DiffVfToSave2 ();
obj.doSave();
}
}
try again once........
All Answers
you should use mandatory fileds in testclass
class:
--------
public with sharing class AccToSave {
public PageReference doSave() {
insert acc;
return (new pagereference('/apex/AccountToSave').setRedirect(true));
}
public Account acc{ get; set; }
public AccToSave(){
acc = new Account();
}
}
test class:
-------------
@isTest
private class TestAccToSave{
static testmethod void myTest(){
AccToSave ats = new AccToSave();
ats.acc.Name = 'SampleAccount';
pagereference ref = ats.doSave();
}
}
Thanks for Your responses that really appreciable, Mahi1 i tried ur code but the code coverage was still same fixed to 62%
try again once........