You need to sign in to do that
Don't have an account?
Marry Stein
Help for testclass
Hey guys,
i am going crazy on this testclass. In my opionion it should be very simple but it does not work.
This is the necessary part of my class.
I would appreciate some advices . Thanks for your help and your time guys !
i am going crazy on this testclass. In my opionion it should be very simple but it does not work.
This is the necessary part of my class.
public class CreateCustomOpporutnityQuote { // create necessary attributes public Opportunity oppo {get; set;} public Id opportunityId {get; set;} public PageReference pdfQuote; public ID parentId {get; set;} // create sections public List <OpportunityLineItem> sectionFlat {get;set;} public List <OpportunityLineItem> sectionEmployerBranding {get;set;} public List <OpportunityLineItem> sectionPerformance {get;set;} public List <OpportunityLineItem> sectionService {get;set;} public List <OpportunityLineItem> sectionSonstiges {get;set;} // variables for customization public String subject {get; set;} public String firsttext {get; set;} public String secondtext {get; set;} public String image {get; set;} public Date qDate {get; set;} // Enddatum für Angebot // pagebreaks between sections public Boolean pageBreak {get; set;} public Boolean pageBreak1 {get; set;} public Boolean pageBreak2 {get; set;} public Boolean pageBreak3 {get; set;} public CreateCustomOpporutnityQuote(ApexPages.StandardController stdController ){ this.oppo = (Opportunity)stdController.getRecord(); this.opportunityId = ApexPages.currentPage().getParameters().get('Id'); } //create pdf sections related to prodcut quote category public void createPdfSections(){ List<OpportunityLineItem> oliList = [Select Id, Name, ListPrice, TotalPrice, Quantity, Product2.CustomQuoteCategory__c, ON_Produktbeschreibung_detailliert__c, Produkt__c, CustomQuoteQuantity__c,Custom_Quote_List_Price__c, Product2.family, Product2.domain__c, Product2.size__c, Product2.Subname__c,SumListPrice__c FROM OpportunityLineItem WHERE OpportunityId =:opportunityId Limit 50]; for(OpportunityLineItem oli : oliList){ switch on oli.Product2.CustomQuoteCategory__c { // Custom when 'BAS' { sectionFlat.add(oli); System.debug('Wenn Category gleich BAS, dann Abschnitt Basis'); } when 'EMP' { sectionEmployerBranding.add(oli); System.debug('Wenn Category EMP, dann Abschnitt Employer Brand'); } when 'PER'{ sectionPerformance.add(oli); System.debug('Wenn Category PER, dann Abschnitt Performane'); } when 'SER'{ sectionService.add(oli); System.debug('Wenn Category SER, dann Abschnitt Service'); } when else { sectionSonstiges.add(oli); System.debug('Wenn nicht zugeordnet, dann Abschnitt Sonstiges'); } } } }so i created the following / testmethode (i think the data setup is not necassary at this point)
@isTest static void testGetOliProd(){ Opportunity opp = [SELECT Id FROM Opportunity LIMIT 1]; ApexPages.StandardController sc = new ApexPages.StandardController(opp); CreateCustomOpporutnityQuote tstCtrl = new CreateCustomOpporutnityQuote(sc); tstCtrl.opportunityId = opp.Id; List<OpportunityLineItem> testList = [Select Id, OpportunityId, Product2.CustomQuoteCategory__c FROM OpportunityLineItem WHERE OpportunityId =: opp.id]; System.assertEquals(testList.size(), 5); List<OpportunityLineItem> bas = new List <OpportunityLineItem>(); List<OpportunityLineItem> emp = new List <OpportunityLineItem>(); List<OpportunityLineItem> perv = new List <OpportunityLineItem>(); List<OpportunityLineItem> serv = new List <OpportunityLineItem>(); List<OpportunityLineItem> sons = new List <OpportunityLineItem>(); Test.startTest(); tstCtrl.createPdfSections(); bas = tstCtrl.sectionFlat; // at this point i get an null pointer exception and i don't know why :( Test.stopTest(); }
I would appreciate some advices . Thanks for your help and your time guys !
First, you need to insert opportunity records in the code than your test class will be covered.
Regards,
Soyab
i did that. I have created all necessary objects in my testSetup method :)
Then i can help you