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
kROOMkROOM 

I dont know how to write a test class for this one. I hope this will be answered since I am new here in Salesforce. Thank you.

public class OpportunityTriggerHandler {
    
    public static void onBeforeInsert(List<Opportunity> opportunityList){
        populateOpp(opportunityList);
    }
    public static void onBeforeUpdate(List<Opportunity> opportunityList, Map<Id,Opportunity> opportunityId){
        populateOppDescription(opportunityList, opportunityId);
    }
    
    public static void populateOpp(List<Opportunity> opportunityList){
        for(Opportunity opp : opportunityList){
            if(opp.StageName == 'Closed Won'){
                opp.Description = 'This Opportunity is Closed Won';
            }
        }
    }
    
    public static void populateOppDescription(List<Opportunity> opportunityList, Map<Id,Opportunity> opportunityId){
        for(Opportunity opp : opportunityList){
            Opportunity oldOpp = opportunityId.get(opp.Id);
            Boolean oldStage = oldOpp.StageName.equals('Closed Won');
            Boolean newStage = opp.StageName.equals('Closed Won');
            
            if(!oldStage && newStage){
                opp.Description = 'This Opportunity is Closed Won';
            }
            
        }
    }
    
    
}
Raj VakatiRaj Vakati
i guess you can calling above code from the trigger so use this code
 
@isTest
private class OpportunityTriggerHandlerTest {
    @isTest static void testCaseOne() {
    
	
	Account newAccount = new Account (
name='XYZ',
Phone = '+1-1212121212',
BillingStreet = 'Am Tierpark 16',
BillingCity = 'Santa Clara',
BillingPostalCode = '95051',
BillingState = 'CA',
BillingCountry = 'USA'
);
insert newAccount;
		
		
	
        Contact c=new Contact(
            FirstName='fname',
            LastName = 'lname',accountid=newAccount.id,
            Email = 'email@gmail.com',
            Phone = '9743800309'); 
        insert c;

		
		
		 // Insert Opportunity
        Opportunity opt = new Opportunity(Name='Test',StageName='Closed Won', 
                                          CloseDate=Date.today(),AccountId= newAccount.Id, Amount=300);
        insert opt;
		
	
	
		 // Insert Opportunity
        Opportunity opt1 = new Opportunity(Name='Test',StageName='Prospect', 
                                          CloseDate=Date.today(),AccountId= newAccount.Id, Amount=300);
        insert opt1;
		
		opt1.StageName='Closed Won' ;
		
		update opt1 ;
	
    }
    
}