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
RuniRuni 

Hi how to write test class for below apex class

public class product1 {
  @AuraEnabled
    public static String updateReviewerComments(String oppId,String cmnt)
    {
        try{
            List<Opportunity> lstOpportunity =new List<Opportunity>();
            System.debug('Started '+oppId +' '+cmnt); 
            Opportunity oppRec=new Opportunity();
            oppRec=[Select Id,CMS_Approved__c,Send_Emails_to_BUH__c From Opportunity where Id=:oppId];
            oppRec.CMS_Approved__c=false;
             oppRec.Send_Emails_to_BUH__c=false;
            //lstOpportunity.add(oppRec);
            System.debug('Started ');
            List<Review_Comments__c> lstReview=new List<Review_Comments__c>();
            Review_Comments__c revcmnt=new Review_Comments__c();
            revcmnt.Comment__c=cmnt;
            revcmnt.Opportunity__c=oppId;
           // lstReview.add(revcmnt);
            String message;  
            Database.SaveResult resultComnt=database.insert(revcmnt,false);
            system.debug('resultComnt'+resultComnt.isSuccess());
            if(resultComnt.isSuccess()){
               
                Database.SaveResult resultOpp=database.update(oppRec,false); 
                 system.debug('resultOpp'+resultOpp.isSuccess());
                if(resultOpp.isSuccess()){
                    return 'Record is reviewed successfully';
                   
                } else {
                    
                    for(Database.Error err : resultOpp.getErrors()) {
                        System.debug('The following error has occurred.');                    
                        return err.getStatusCode() + ': ' + err.getMessage();
                        
                    }
                }
                
            } else {
                // Operation failed, so get all errors                
                for(Database.Error err : resultComnt.getErrors()) {
                    System.debug('The following error has occurred.');                    
                    return err.getStatusCode() + ': ' + err.getMessage();
                   
                }
            }
            //System.debug('Enterted  '+revcmnt);
           // System.debug('Opp Record value  '+oppRec);
            // Create an approval request for the Opportunity
            
            return message;
        }
        catch(exception e)
        {
            return e.getMessage();
        }
    }
}
CharuDuttCharuDutt
Hii Surrender 
Try Below Test Class
@isTest 
 public Class product1Test { 
 @isTest
 public Static Void unitTest(){
	Opprotunity opp = new opportunity();
	opp.name ='test opp';
	opp.StageName = 'Closed Won';
	Opp.CloseDate = System.Today();
	Insert opp;
	
	
	product1.updateReviewerComments(opp.id,'Test Comment');
 }
 }
Please Mark It As Best Answer If It Helps
Thank You!
RuniRuni
Hicharudatt, 

I am getting below error. 
updateReviewerComments(I'd, string) from the  product1. 
CharuDuttCharuDutt
Hii Surrender
Try Below Class
@isTest 
 public Class product1Test { 
 @isTest
 public Static Void unitTest(){
	opportunity opp = new opportunity();
	opp.name ='test opp';
	opp.StageName = 'Closed Won';
	Opp.CloseDate = System.Today();
	Insert opp;
	
	
	product1.updateReviewerComments(opp.id,'Test Comment');
 }
 }
Please Mark It As Best Answer If It Helps
Thank You!