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
Sebastian PageSebastian Page 

Need help on Test class and code coverage

Hello All,  I am facing issue on test  class. My test class execute successfully but code coverage is None please Help.
My apex class here
@istest
public class CommenttoEmailTest {
    
    static testMethod void testMatching(){
        
        
     
        //  Id rtId = [select Id, name from RecordType where name = 'Massbay_Ticket' and SObjectType = 'Case' limit 1].Id;
    

    //create account
    Account acc = new Account();
    //enter details  
    acc.Name = 'Test Account';
     //Add other fields
    insert acc;
  
   // create test contact
        Contact con = TestUtilityController.getContact('Test Last Name','testing@testing.com',acc.Id);
        insert con;  
    
     
        
        // Create test cases
        List<Case> listCase = new List<Case>();
        
        if(UtilityController.caseRecordType.containsKey('Massbay_Ticket')){
            String recordTypeId = UtilityController.caseRecordType.get('Massbay_Ticket').Id;
            
            Case csa = TestUtilityController.getCase(recordTypeId,con.Id,acc.Id);
           
                    //enter details
                   
                      //Add other fields
                      csa.Ticket_Category__c='Blackboard learn';
                        csa.Status = 'Action-Automated Escalation';
   
                           insert csa;
    
    PageReference pageRef = Page.MyNew_commentvf;
     pageRef.getParameters().put(recordTypeId, String.valueOf(csa.Id));
     Test.setCurrentPage(pageRef);  
     
     CaseComment tComment = new CaseComment();
        tComment.ParentId = Csa.Id;
        tComment.CommentBody = 'Some Comment';
        tComment.IsPublished = TRUE;
        
        insert tComment;
        
        
 tComment.CommentBody = 'Inporgreess  Comment';
     update tComment ;   
     

      ApexPages.StandardController sc = new ApexPages.StandardController(csa);
     CommenttoEmail  testCmEmail = new CommenttoEmail (sc);
testCmEmail.senttoEmail();
testCmEmail.bccEmail();
testCmEmail.ccEmail();
testCmEmail.attachemail();
testCmEmail.createCaseComment();
testCmEmail.sendingEmail();
testCmEmail.ss();
  testCmEmail.ChangeStatus();
testCmEmail.getCaseStatus();
testCmEmail.upload();  
     
        
        }    
        
        
    }// end of test method
    

    
}// end of Class

and my test class is 
@istest
public class CommenttoEmailTest {
    
    static testMethod void testMatching(){
        
        
     
        //  Id rtId = [select Id, name from RecordType where name = 'Massbay_Ticket' and SObjectType = 'Case' limit 1].Id;
    

    //create account
    Account acc = new Account();
    //enter details  
    acc.Name = 'Test Account';
     //Add other fields
    insert acc;
  
   // create test contact
        Contact con = TestUtilityController.getContact('Test Last Name','testing@testing.com',acc.Id);
        insert con;  
    
     
        
        // Create test cases
        List<Case> listCase = new List<Case>();
        
        if(UtilityController.caseRecordType.containsKey('Massbay_Ticket')){
            String recordTypeId = UtilityController.caseRecordType.get('Massbay_Ticket').Id;
            
            Case csa = TestUtilityController.getCase(recordTypeId,con.Id,acc.Id);
           
                    //enter details
                   
                      //Add other fields
                      csa.Ticket_Category__c='Blackboard learn';
                        csa.Status = 'Action-Automated Escalation';
   
                           insert csa;
    
    PageReference pageRef = Page.MyNew_commentvf;
     pageRef.getParameters().put(recordTypeId, String.valueOf(csa.Id));
     Test.setCurrentPage(pageRef);  
     
     CaseComment tComment = new CaseComment();
        tComment.ParentId = Csa.Id;
        tComment.CommentBody = 'Some Comment';
        tComment.IsPublished = TRUE;
        
        insert tComment;
        
        
 tComment.CommentBody = 'Inporgreess  Comment';
     update tComment ;   
     

      ApexPages.StandardController sc = new ApexPages.StandardController(csa);
     CommenttoEmail  testCmEmail = new CommenttoEmail (sc);
testCmEmail.senttoEmail();
testCmEmail.bccEmail();
testCmEmail.ccEmail();
testCmEmail.attachemail();
testCmEmail.createCaseComment();
testCmEmail.sendingEmail();
testCmEmail.ss();
  testCmEmail.ChangeStatus();
testCmEmail.getCaseStatus();
testCmEmail.upload();  
     
        
        }    
        
        
    }// end of test method
    

    
}// end of Class
Raj VakatiRaj Vakati
Try this  and ckechthe test class is failing or not

 
@istest
public class CommenttoEmailTest {

static testMethod void testMatching(){
				
			Id rtId = [select Id, name from RecordType where name = 'Massbay_Ticket' and SObjectType = 'Case' limit 1].Id;

			//create account
			Account acc = new Account();
			//enter details  
			acc.Name = 'Test Account';
			 //Add other fields
			insert acc;

     Contact con = TestUtilityController.getContact('Test Last Name','testing@testing.com',acc.Id);
	insert con;  

	// Create test cases
	List<Case> listCase = new List<Case>();
	
		
		      Case csa = TestUtilityController.getCase(rtId,con.Id,acc.Id);
				//enter details
				  //Add other fields
				  csa.Ticket_Category__c='Blackboard learn';
					csa.Status = 'Action-Automated Escalation';
					   insert csa;
					   
					   CaseComment tComment = new CaseComment();
	tComment.ParentId = Csa.Id;
	tComment.CommentBody = 'Some Comment';
	tComment.IsPublished = TRUE;
	
	insert tComment;
	
	

PageReference pageRef = Page.MyNew_commentvf;
 pageRef.getParameters().put(recordTypeId, String.valueOf(csa.Id));
 Test.setCurrentPage(pageRef);  
 
 
   
 

  ApexPages.StandardController sc = new ApexPages.StandardController(csa);
 CommenttoEmail  testCmEmail = new CommenttoEmail (sc);
testCmEmail.senttoEmail();
testCmEmail.bccEmail();
testCmEmail.ccEmail();
testCmEmail.attachemail();
testCmEmail.createCaseComment();
testCmEmail.sendingEmail();
testCmEmail.ss();
testCmEmail.ChangeStatus();
testCmEmail.getCaseStatus();
testCmEmail.upload();  
 
	
	  
	
	
}// end of test method



}// end of Class

 
Sebastian PageSebastian Page
Hi raj ,
Method failed again with to many soql query  101 error.