Skip to main content
Hi Guys,

 

I am testing a triggerhandlerclass and it's giving only 45% code coverage, it's not covering after line 16 please help :

 

Handler Class:

 

public class SumQuoteHandler {

 

    Public static set<Id> ids = new set<Id>();

 

        Public    static    Decimal amount = 0;

 

        Public  Static decimal amount1 = 0;

 

        Public  static decimal amount2 = 0;

 

    Public static void sumQuotefeld(List<QuoteLineItem>QLL){

 

        for(QuoteLineItem QLII : QLL){

 

            ids.add(QLII.QuoteId);

 

        }

 

        system.debug(ids);

 

        List<Quote> QI = [SELECT Id, Rabatt_der_einmaligen_Geb_hren__c, einmalige_Geb_hren__c, monatlicher_LP_Lizenzen__c  FROM Quote where Id =:ids]; // where Id IN:ids

 

        system.debug(QI);

 

        List<QuoteLineItem> QL = [SELECT id, QuoteId,Produktkategorie__c, isdeleted, GesamtpreisNEU__c, Euro_Rabatt_del__c, ListPrice FROM QuoteLineItem WHERE QuoteId IN: QI ];

 

        system.debug(QL);// line 17

 

            for(QuoteLineItem QQ : QL){

 

                for (Quote Q : QI){

 

               // system.debug(QQ);

 

                if(Q.id==QQ.QuoteId && Q.Id!=null && QQ.Euro_Rabatt_del__c!=null && QQ.GesamtpreisNEU__c!=null && QQ.Produktkategorie__c!='Software Subscription'){

 

                    system.debug(QQ);

 

                          amount += QQ.Euro_Rabatt_del__c;

 

                        amount1 += QQ.GesamtpreisNEU__c;

 

                }

 

                else if(Q.id==QQ.QuoteId && Q.Id!=null && QQ.ListPrice!=null && QQ.Produktkategorie__c=='Software Subscription'){

 

                    amount2 += QQ.ListPrice;

 

                }

 

                Q.Rabatt_der_einmaligen_Geb_hren__c = amount;

 

                Q.einmalige_Geb_hren__c = amount1;

 

                Q.monatlicher_LP_Lizenzen__c = amount2;

 

                    update Q;

 

            }

 

            }

 

}

 

}

 

Test Class :

 

@isTest

 

private class TestSumQuoteHandlerTest {

 

        Public static Decimal amount = 0;

 

        Public Static decimal amount1 = 0;

 

        Public Static decimal amount2 = 0;

 

    @isTest static void TestsumQuotefeld() { 

 

    

 

    Account acc = new Account (name='Acme',CustomCountry__c = 'Deutschland');

 

        insert acc;

 

        Opportunity opp= new Opportunity ();

 

        opp.name= 'Testopp';

 

        Opp.Accountid= acc.id;

 

        opp.CloseDate= date.today();

 

        opp.StageName= 'Qualification';

 

        insert opp;

 

Pricebook2 pb = new Pricebook2(Name = 'Standard Price Book 2009', Description = 'Price Book 2009 Products', IsActive = true );

 

    insert pb;

 

Product2 prod = new Product2(Name = 'SLA: Bronze', IsActive = true);

 

    insert prod;

 

PricebookEntry pbe=new PricebookEntry(unitprice=0.01,Product2Id=prod.Id, Pricebook2Id=Test.getStandardPricebookId(), IsActive= true);

 

     insert pbe;  

 

        Quote q= new Quote ();

 

             q.Name= 'Testq';

 

            Q.Rabatt_der_einmaligen_Geb_hren__c = 1;

 

            Q.einmalige_Geb_hren__c = 1;

 

            Q.monatlicher_LP_Lizenzen__c = 0;

 

            q.OpportunityId= Opp.id;

 

            q.BillingStreet= '123';

 

            q.BillingCity= 'City';

 

            q.BillingPostalCode= '12345';

 

            q.Pricebook2Id= Test.getStandardPricebookId();

 

            insert q;

 

        

 

          QuoteLineItem qli= new QuoteLineItem();

 

            qli.QuoteId=q.Id;

 

            qli.PricebookEntryid= pbe.Id;

 

            qli.quantity=2;

 

            qli.UnitPrice = 1;

 

        Qli.GesamtpreisNEU__c = 2;

 

        Qli.Euro_Rabatt_del__c = 2;

 

        Qli.Description = 'Test2';

 

          Qli.Quantity = 2;

 

        insert qli;

 

        List<QuoteLineitem> QLL = New List<Quotelineitem>();

 

        List<Quote> QL = New List<Quote>();

 

        sumquoteHandler.sumQuotefeld(QLL);

 

        //opp.StageName= 'Closed Won';

 

        system.assert(QLI!=null);

 

        

 

        }        

 

    }

 

I shall be grateful to you for your kind response.
답변 4개
  1. 2020년 7월 24일 오전 5:01
    Hi, 

     

    It seems your test method does  it add your quote line item to the list that's passed on to the actual code. Try this:

     

    List<QuoteLineitem> QLL = New List<Quotelineitem>();

     

    QLL.add(qli);

     

    sumquoteHandler.sumQuotefeld(QLL);
0/9000