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
Feel Free To AskFeel Free To Ask 

I have created an Apex class but don't know how to write its test class. Can anyone help me in writing its test class. Please.

public class printpdf {
    public List<QuoteLineItem> prd{get;set;}
    private final ApexPages.StandardController theController;
    
    public printpdf(ApexPages.StandardController controller) {
        theController = controller;
        
    prd = [Select Id , QuoteId, Product2Id, Product2.Name, Product2.Description, Product2.ProductCode, Product2.Cross_Distr_Channel_Status__c, Product2.GB_Enterprise_Prod_Hier_Level_5__c from QuoteLineItem where QuoteId=:thecontroller.getId()];
    }
}
AnkaiahAnkaiah (Salesforce Developers) 
Hi Suvimal,

Try with below code. Modify the data as per your need.
@isTest 

    public class TestCreateQuote 
    {
    Static testMethod void TestCreateQuote(){

        Account a = new Account(name='acc1');
    insert a;
        Opportunity o = new Opportunity();

        o.Accountid = a.id;
        o.Name = 'test';
        o.StageName = 'Prospecting';
        o.CloseDate = date.today();
        o.Project_Type_test__c = 'Training';
        o.Remuneration_Model__c = 'Fees Only';
        o.Type = 'New Client';
        o.NextStep = 'Test';
        o.LeadSource = 'Business Development';
        insert o;
		
		Quote quote = new Quote(Name = 'devis1' ,
                        OpportunityId=o.Id,
                        Pricebook2Id =  Test.getStandardPricebookId() );
insert quote;  

Product2 pr1 = new Product2(Name = 'test');
        insert pr1;
PriceBookEntry pre = new PriceBookEntry(
         IsActive = true,
         PriceBook2Id = Test.getStandardPricebookId(), 
         Product2Id = pr1.Id , 
         UnitPrice=123);
insert pre;

      test.startTest();
		
			ApexPages.StandardController sc = new ApexPages.StandardController(testAccount);
			printpdf  pdf = new printpdf(sc);
pdf.save();
			
		test.stopTest()

        }
    }

If this helps, please mark it as best answer.

Thanks!!