You need to sign in to do that
Don't have an account?
Testing a New Class
Hi, I'm fairly new to Apex and I'm a little confused how the testing works. I have the following really small class but can't seem to figure out how to write the test to cover 75%. Can anyone help?
public class findSLCFamily { private final List<SLC__c> slcs; private final SLC__c currentSLC; public findSLCFamily() { currentSLC = [select Original_SLC__c from SLC__c where id = :ApexPages.currentPage().getParameters().get('id')]; slcs = [select Name, License_Order__c, Product__c, Devices__c, SUP_End_Date__c, Original_SLC__c from SLC__c where Original_SLC__c = :currentSLC.Original_SLC__c order by License_Order__c]; } public List<SLC__c> getSLCFamily() { return slcs; } }
public class findSLCFamily { private final List<SLC__c> slcs; private final SLC__c currentSLC; public findSLCFamily() { currentSLC = [select Original_SLC__c from SLC__c where id = :ApexPages.currentPage().getParameters().get('id')]; slcs = [select Name,Original_SLC__c from SLC__c where Original_SLC__c = :currentSLC.Original_SLC__c ]; } public List<SLC__c> getSLCFamily() { return slcs; } public static testMethod void findSLCFamily_Test() { List<SLC__c> divList = new List<SLC__c>(); for(Integer i=0;i<15;i++) { SLC__c div = new SLC__c(Name='ram',Original_SLC__c='radhika'); divList.add(div); } insert divList; SLC__c sl = new SLC__C(Name='Test SLC',Original_SLC__c='radhika'); insert sl; ApexPages.currentPage().getParameters().put('id',sl.Id); findSLCFamily f=new findSLCFamily(); f.getSLCFamily(); } }
I got 100% coverage for the above code try it.
For any other information feel free to contact us.
DSKVAP developer's Team
Dskvap technologies.
email:kumar77@dskvap.com
All Answers
public class findSLCFamily { private final List<SLC__c> slcs; private final SLC__c currentSLC; public findSLCFamily() { currentSLC = [select Original_SLC__c from SLC__c where id = :ApexPages.currentPage().getParameters().get('id')]; slcs = [select Name,Original_SLC__c from SLC__c where Original_SLC__c = :currentSLC.Original_SLC__c ]; } public List<SLC__c> getSLCFamily() { return slcs; } public static testMethod void findSLCFamily_Test() { List<SLC__c> divList = new List<SLC__c>(); for(Integer i=0;i<15;i++) { SLC__c div = new SLC__c(Name='ram',Original_SLC__c='radhika'); divList.add(div); } insert divList; SLC__c sl = new SLC__C(Name='Test SLC',Original_SLC__c='radhika'); insert sl; ApexPages.currentPage().getParameters().put('id',sl.Id); findSLCFamily f=new findSLCFamily(); f.getSLCFamily(); } }
I got 100% coverage for the above code try it.
For any other information feel free to contact us.
DSKVAP developer's Team
Dskvap technologies.
email:kumar77@dskvap.com