You need to sign in to do that
Don't have an account?
Girbson Bijou 8
Test Class Coverage Increasing
Please help me to increase the code coverage of this class. actually is is only at 25%. the class is to increment in field each time a visualforce page called "DeliveryPage" is launched. This field is on an object called Delivery__c which is a child of Account
Test Class
public class DeliveryPageClass { // public Delivery__c delivery{get;set;} public id deliveryId; public DeliveryPageClass(ApexPages.StandardController stdController) { deliveryId=stdController.getId(); } public void updateDelivery() { Delivery__c delivery = [select id,Print_Counter__c from Delivery__c where id=:deliveryId]; if(delivery.Print_Counter__c==null) { delivery.Print_Counter__c=1; } else { delivery.Print_Counter__c=delivery.Print_Counter__c+1; } system.debug(delivery); update delivery; system.debug(delivery); } }
Test Class
@isTest public class DeliveryPageClassTest { static testMethod void TestDeliveryPageClass(){ Account pa = new Account(Name ='test Account parent', Representant__c ='hkjlhjd', Distribution_Center__c='CRD Cayes', Class__c = 'Clinic', Type = 'CLINICS', Departement__c = 'NORD', Address__c ='Test Address'); insert pa; Account a = new Account(); a.Name ='test Account'; a.Representant__c ='Bijou'; a.Distribution_Center__c='FFP Caracole'; a.Class__c = 'NGO'; a.Type = 'CLINICS'; a.Departement__c = 'NORD'; a.Address__c ='Test Address'; a.ParentId = pa.ID; insert a ; Delivery__c del = new Delivery__c(); del.Beneficiaire__c = a.Id; del.Ration__c =3; del.Delivery_status__c='Pending'; insert del; ApexPages.StandardController sc = new ApexPages.standardController(new Delivery__c()); DeliveryPageClass dpc = new DeliveryPageClass(sc); } }
Please try the below test class:
@isTest
public class DeliveryPageClassTest {
static testMethod void TestDeliveryPageClass(){
Account pa = new Account(Name ='test Account parent', Representant__c ='hkjlhjd',
Distribution_Center__c='CRD Cayes', Class__c = 'Clinic', Type = 'CLINICS',
Departement__c = 'NORD', Address__c ='Test Address');
insert pa;
Account a = new Account();
a.Name ='test Account';
a.Representant__c ='Bijou';
a.Distribution_Center__c='FFP Caracole';
a.Class__c = 'NGO';
a.Type = 'CLINICS';
a.Departement__c = 'NORD';
a.Address__c ='Test Address';
a.ParentId = pa.ID;
insert a ;
Delivery__c del = new Delivery__c();
del.Beneficiaire__c = a.Id;
del.Ration__c =3;
del.Delivery_status__c='Pending';
del.Print_Counter__c = 1;
insert del;
ApexPages.StandardController sc = new ApexPages.standardController(del);
DeliveryPageClass dpc = new DeliveryPageClass(sc);
dpc.updateDelivery();
}
static testMethod void TestDeliveryPageClass1(){
Account pa = new Account(Name ='test Account parent', Representant__c ='hkjlhjd',
Distribution_Center__c='CRD Cayes', Class__c = 'Clinic', Type = 'CLINICS',
Departement__c = 'NORD', Address__c ='Test Address');
insert pa;
Account a = new Account();
a.Name ='test Account';
a.Representant__c ='Bijou';
a.Distribution_Center__c='FFP Caracole';
a.Class__c = 'NGO';
a.Type = 'CLINICS';
a.Departement__c = 'NORD';
a.Address__c ='Test Address';
a.ParentId = pa.ID;
insert a ;
Delivery__c del = new Delivery__c();
del.Beneficiaire__c = a.Id;
del.Ration__c =3;
del.Delivery_status__c='Pending';
del.Print_Counter__c = null;
insert del;
ApexPages.StandardController sc = new ApexPages.standardController(del);
DeliveryPageClass dpc = new DeliveryPageClass(sc);
dpc.updateDelivery();
}
}
Thanks,
Maharajan.C
All Answers
Please try the below test class:
@isTest
public class DeliveryPageClassTest {
static testMethod void TestDeliveryPageClass(){
Account pa = new Account(Name ='test Account parent', Representant__c ='hkjlhjd',
Distribution_Center__c='CRD Cayes', Class__c = 'Clinic', Type = 'CLINICS',
Departement__c = 'NORD', Address__c ='Test Address');
insert pa;
Account a = new Account();
a.Name ='test Account';
a.Representant__c ='Bijou';
a.Distribution_Center__c='FFP Caracole';
a.Class__c = 'NGO';
a.Type = 'CLINICS';
a.Departement__c = 'NORD';
a.Address__c ='Test Address';
a.ParentId = pa.ID;
insert a ;
Delivery__c del = new Delivery__c();
del.Beneficiaire__c = a.Id;
del.Ration__c =3;
del.Delivery_status__c='Pending';
del.Print_Counter__c = 1;
insert del;
ApexPages.StandardController sc = new ApexPages.standardController(del);
DeliveryPageClass dpc = new DeliveryPageClass(sc);
dpc.updateDelivery();
}
static testMethod void TestDeliveryPageClass1(){
Account pa = new Account(Name ='test Account parent', Representant__c ='hkjlhjd',
Distribution_Center__c='CRD Cayes', Class__c = 'Clinic', Type = 'CLINICS',
Departement__c = 'NORD', Address__c ='Test Address');
insert pa;
Account a = new Account();
a.Name ='test Account';
a.Representant__c ='Bijou';
a.Distribution_Center__c='FFP Caracole';
a.Class__c = 'NGO';
a.Type = 'CLINICS';
a.Departement__c = 'NORD';
a.Address__c ='Test Address';
a.ParentId = pa.ID;
insert a ;
Delivery__c del = new Delivery__c();
del.Beneficiaire__c = a.Id;
del.Ration__c =3;
del.Delivery_status__c='Pending';
del.Print_Counter__c = null;
insert del;
ApexPages.StandardController sc = new ApexPages.standardController(del);
DeliveryPageClass dpc = new DeliveryPageClass(sc);
dpc.updateDelivery();
}
}
Thanks,
Maharajan.C