You need to sign in to do that
Don't have an account?
Staci
Test Class Help Please
I have a test class started, got the dummy data created and now I'm not sure where to go.
How do you write a test class for all this?? Can't SF create something that would automatically create the test class for you????
How do you write a test class for all this?? Can't SF create something that would automatically create the test class for you????
public with sharing class LicenseList { private final License_Numbers__c ln; public user currentuser{get;set;} public id tobeEdited{get;set;} public decimal aTotal{get;set;} public decimal tTotal{get;set;} public id tobeAdded{get;set;} public List<AccountWrapper> wrappers{get;set;} public static Integer addCount{get;set;} private Integer nextIdent=0; public LicenseList(ApexPages.StandardSetController controller) { currentuser=new User(); currentuser=[Select Id, Business_Unit_new__c from User where Id=:userinfo.getuserId()]; this.ln = (License_Numbers__c)controller.getRecord(); wrappers=new List<AccountWrapper>(); for(Integer idx=0; idx<1; idx++) { wrappers.add(new AccountWrapper(nextIdent++)); } } //------------------------------------------------------------------------------------ public List<License_Numbers__c> lntypes16 = new List<License_Numbers__c>(); public List <License_Numbers__c> getLicenseList(){ lntypes16 = [select id, Name, X2016_Cost__c, Business_Unit__c, X2016_Starting_Amount__c, X2016_Subtotal__c, BMS_Code__c, License_Type__c, Monthly_Unit_Price__c, Running_License_Total__c, Org__c FROM License_Numbers__c where Business_Unit__c =:currentuser.Business_Unit_new__c AND License_Year__c = '2016' ORDER BY Order_Number__c, License_Type__c]; return lntypes16; } //----------------------------------------------------------------------------- public List<License_Numbers__c> selectedTypes = new List<License_Numbers__c>(); public List <License_Numbers__c> getLicenseList17(){ selectedTypes=[select id, Name, BU_Agrees_to_Pay__c, Annualized_Running_Total__c, X2017_Cost__c, Business_Unit__c,X2017_Total_Needed__c, X2016_Starting_Amount__c, X2017_Subtotal__c, BMS_Code__c, License_Type__c, Monthly_Unit_Price__c, Org__c FROM License_Numbers__c where Business_Unit__c =:currentuser.Business_Unit_new__c AND License_Year__c = '2017' ORDER BY Order_Number__c, License_Type__c]; aTotal = 0.0; tTotal = 0.0; for(License_Numbers__c a:selectedTypes){ aTotal = aTotal + a.X2017_Cost__c; tTotal = tTotal + a.X2017_Subtotal__c; } return selectedTypes; } public void saveRecord(){ License_Numbers__c tobeupdated; for(License_Numbers__c temp:selectedTypes){ if(temp.id==tobeEdited){ tobeupdated = temp; } } update selectedTypes; tobeEdited = null; } //-------------------------------------------------------------------------------------------- public List<License_Numbers__c> addlic {get; set;} public PageReference save() { List<License_Numbers__c> addlic=new List<License_Numbers__c>(); for(AccountWrapper wrap:wrappers) { addlic.add(wrap.lic); } insert addlic; return new PageReference('/apex/LicenseSummaryHomePage'); } public class AccountWrapper { public License_Numbers__c lic{get; private set;} public Integer ident{get; private set;} public AccountWrapper(Integer inIdent) { ident=inIdent; lic=new License_Numbers__c(); } } //------------------------------------------------------------------------------------------- public SelectOption[] getSchedules() { return new SelectOption[] { new SelectOption('Value0', '--None--'), new SelectOption('Value1', 'Value1'), new SelectOption('Value2', 'Value2'), }; } public String discountScheduleID { get; set; } //-------------------------------------------------------------- Public string OutPutString{get;set;} Public String SelectOption; public void displayDescription(){ if (discountScheduleID == 'Value1') { OutPutString = 'No Description Available' ; }else if (discountScheduleID == 'Value2') { OutPutString = 'No Description Available' ; }}
@isTest private class LicenseListTest{ static testMethod void LicenseListTest(){ Profile p = [SELECT Id FROM Profile WHERE Name='Community Super User' limit 1]; //create a user UserRole r = [SELECT Id FROM userrole WHERE name = 'CM User' limit 1]; User u1 = new User(LastName = 'Test Class', Username = 'CRMUser@Test.com', UserRoleId = r.Id, Email = 'CRMUser@Test.com', Alias = 'tclass', CommunityNickname = 'tclass', TimeZoneSidKey = 'Asia/Kolkata', LocaleSidKey = 'en_US', EmailEncodingKey = 'UTF-8', ProfileId = p.Id, LanguageLocaleKey = 'en_US', Business_Unit__c = 'GCI'); insert u1; } static testMethod void LicenseList_test() { //create a license Record License_Numbers__c ln1 = new License_Numbers__c( Business_Unit__c = 'GCI', X2016_Starting_Amount__c = 5, BMS_Code__c = 'X1357', License_Type__c = 'Service Cloud - Unlimited Edition', Monthly_Unit_Price__c = 83.00, Running_License_Total__c = 500, Org__c = 'CRM Innovation', License_Year__c = '2016'); insert ln1; //create a license Record License_Numbers__c ln2 = new License_Numbers__c( Business_Unit__c = 'GCI', X2016_Starting_Amount__c = 5, BMS_Code__c = 'X1357', License_Type__c = 'Analytics Cloud - Wave Analytics Platform', Monthly_Unit_Price__c = 52.50, Org__c = 'CRM Innovation', License_Year__c = '2016'); insert ln2; } static testMethod void LicenseList17_test() { //create a license Record License_Numbers__c ln3 = new License_Numbers__c( Business_Unit__c = 'GCI', X2016_Starting_Amount__c = 5, BMS_Code__c = 'X1357', License_Type__c = 'Service Cloud - Unlimited Edition', Monthly_Unit_Price__c = 83.00, Running_License_Total__c = 500, Org__c = 'CRM Innovation', License_Year__c = '2017'); insert ln3; //create a license Record License_Numbers__c ln4 = new License_Numbers__c( Business_Unit__c = 'GCI', X2016_Starting_Amount__c = 5, BMS_Code__c = 'X1357', License_Type__c = 'Analytics Cloud - Wave Analytics Platform', Monthly_Unit_Price__c = 52.50, Org__c = 'CRM Innovation', License_Year__c = '2017'); insert ln4; } }
Could you also post your visualforce page associated with this apex class.
Thanks
I'm starting to get some coverage, but can you help me cover the
public SelectOption[] getSchedules() {
part?
Here's what I have so far for everything else - its not complete, but its getting there.
Thanks!
@SFDC_BigDog
I have almost everything covered excep the OutPutString lines. How do I get those covered?