-2
public with sharing class CreateQuotePDFController {
    public list<QuoteLineItem> quoteLineItemsList{get;set;}
    public Id getid{get;set;} 
    public Double grandTotalTax{get;set;}
    public Double finalPO{get;set;}
    public Date expirationDate{get;set;}
    public CreateQuotePDFController(ApexPages.StandardController controller) {
        getid=ApexPages.currentPage().getParameters().get('id');
        Quote quote = [SELECT Account.Name, Account.BillingCountry,Account.BillingPostalCode,Account.BillingState,Account.BillingCity,Account.BillingStreet, Contact.Name, GrandTotal, ExpirationDate FROM quote where id=:getid ];
        quoteLineItemsList = [select id,product2id,Discount_Percentage__c, PricebookEntry.Product2.Name , UnitPrice, Quantity, Subtotal from quotelineitem where QuoteId=: getid];        
        System.debug('grand total is : ' +quote.GrandTotal);
        grandTotalTax = (quote.GrandTotal * 0.18).setScale(2);
        finalPO = (quote.GrandTotal+grandTotalTax).setScale(2);
        expirationDate = quote.ExpirationDate;
    }
}

Test Class :-

@isTest
public class CreateQuotePDFController_Test {
@testsetup static void data_setup(){
Account acc1 = new Account();
        acc1.Name = 'test account';
        insert acc1;
        system.debug('insert acc1 is success');

        Opportunity Opp1 = new Opportunity();
        Opp1.Name = 'testOpp';
        Opp1.AccountId = acc1.Id;
        Opp1.StageName = 'Closed Won';
        Opp1.CloseDate = system.Today();
        insert Opp1;        
        system.debug('insert opp1 success');

        Product2 Pro1 = new Product2();
        Pro1.Name = 'SLA: Bronze';
        pro1.isActive = True;
        Insert pro1;
        system.debug('insert pro1 is success');        

        Pricebook2 pb = new pricebook2();
        pb.Name = 'Standard Price Book 2009';
        pb.description = 'Price Book 2009 Products';
        pb.isActive = True;
        insert pb;
        system.debug('pb value is'+ pb.Id);
        system.debug('insert pricebook2 is success');

        Id pricebookId = Test.getStandardPricebookId();        

        PricebookEntry StandardPriceBookEntry = new PricebookEntry();
        StandardPriceBookEntry.Pricebook2Id = pricebookId;
        StandardPriceBookEntry.Product2Id = pro1.Id;
        StandardPriceBookEntry.UnitPrice = 10000;
        StandardPriceBookEntry.IsActive =True;        
        insert StandardPriceBookEntry;
        system.debug('insert StandardPriceBookEntry');

        PricebookEntry pbe = new PricebookEntry(pricebook2id=pb.id, product2id=pro1.id, unitprice=10000, isActive = True);
        insert pbe;
        system.debug('insert pbe is success');

        Quote Quo1 = new Quote(); 
        Quo1.OpportunityId = Opp1.Id;
        Quo1.Pricebook2Id = pb.Id;
        Quo1.Name = 'test Quo1';      
        insert Quo1;       
        system.debug('insert Quo1 success');

        QuoteLineItem QLI  = new QuoteLineItem();
        QLI.Product2Id = pro1.Id;
        QLI.QuoteId = Quo1.Id;
        QLI.PricebookEntryId = Pbe.Id;
        QLI.Quantity = 2;
        QLI.UnitPrice = 150000.0; 
        insert QLI;    
        system.debug('insert QLI is success');
     
    ApexPages.StandardController sc = new ApexPages.StandardController(Quo1);
    CreateQuotePDFController qpc = new CreateQuotePDFController(sc);
    PageReference pageRef = Page.CreateQuotePDF;
    Test.setCurrentPage(pageRef);
    pageRef.getParameters().put('id', String.valueOf(Quo1.Id));
    Test.startTest();
     Quo1 = [SELECT Account.Name, Account.BillingCountry,Account.BillingPostalCode,Account.BillingState,Account.BillingCity,Account.BillingStreet, Contact.Name, GrandTotal, ExpirationDate FROM quote where id=:Quo1.Id ];
     QLI = [select id,product2id,Discount_Percentage__c, PricebookEntry.Product2.Name , UnitPrice, Quantity from quotelineitem where QuoteId=:Quo1.Id];
       Test.stopTest();
   system.assert(Quo1 != null);
     
       
   } 
     
    
}
0

1 Answer 1

2

The class CreateQuotePDFController_Test contains no unit test methods. It contains only a test data setup method, data_setup(), which appears to also contain the start of a unit test but no assertions to validate behavior.

You need to write at least one actual unit test method. Please review How do I write an Apex unit test? for introductory resources. Every unit test should contain at least three elements:

  • Data setup (which you've already done)
  • Execution of functionality (which you've at least started to do, but in the wrong place)
  • Assertions about behavior (which you need to add)
3
  • I Tried to add Assertion but same issue. Quo1 = [SELECT Account.Name, Account.BillingCountry,Account.BillingPostalCode,Account.BillingState,Account.BillingCity,Account.BillingStreet, Contact.Name, GrandTotal, ExpirationDate FROM quote where id=:Quo1.Id ]; QLI = [select id,product2id,Discount_Percentage__c, PricebookEntry.Product2.Name , UnitPrice, Quantity from quotelineitem where QuoteId=:Quo1.Id]; Test.stopTest(); system.assert(Quo1 != null);
    – user105753
    Oct 10, 2021 at 5:12
  • Why are you simply closing the question, i just asked for help, if you won't, please let this open so that someone will help me with my problem.
    – user105753
    Oct 10, 2021 at 13:16
  • I did not close this question. The root problem is that you have no test methods (@isTest). Again, this is something you can explore by reviewing the introductory materials on unit test creation.
    – David Reed
    Oct 10, 2021 at 16:06

Not the answer you're looking for? Browse other questions tagged or ask your own question.