function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Akash Garg 2Akash Garg 2 

need test class for apex class

Hi

Please help to write the TEST class for the following apex class:-
public with sharing class Controller_QuotePage {
   public Opportunity qt {get; set;}
   public List<Opportunity_Product__c> theLineItems {get; set;}
   public Controller_QuotePage(ApexPages.StandardController controller) 
   {
       Id quoteID = ((Opportunity) controller.getRecord()).Id;
       loadQuote(quoteId);
       loadQuoteLineItems(quoteId);
    }
    
    public List<Opportunity_Product__c> getLineItems(){
         
         return theLineItems;
    }
    

   private void loadQuote(String quoteId) {
        this.qt = [Select Id, Name       
                   FROM Opportunity where    
                  Id=:quoteId];  
      
   }
    
   private void loadQuoteLineItems(String quoteId) {

       this.theLineItems = [SELECT Id, Name                          
                             FROM Opportunity_Product__c WHERE Opportunity__c =:   
                             quoteId];  
            
    }


}

 
Manoj DegaManoj Dega
Hi Akash,

Please find this code. Hope it helps for you.
 
@istest
public class Controller_QuotePageTest{
	static testMethod void cpq(){
		Opportunity opt = new Opportunity ();
			opt.name = 'Test Opportunity';
			opt.StageName = 'prospecting';
			opt.closedate = System.today();
			insert opt;
		Opportunity_Product__c oppProduct = new Opportunity_Product__c();
			oppProduct.Opportunity__c = opt.id;
			insert oppProduct;
			
			ApexPages.StandardController sc = new ApexPages.StandardController(opt);
			Controller_QuotePage testAccPlan = new Controller_QuotePage(sc);
			testAccPlan.getLineItems();
	}
}

Please choose the best answer, if this helps you.
Thank you