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
GhanesanGhanesan 

Code Coverage is None, overall coverage is also 0%

Hi, 

Trying to run the test but for some reason my test code coverage shows None. Here is my code

Class:

public with sharing class emailHelper {
public Aspirant__c asp {get;set;}    
public User myUser { get;set;}

public emailHelper(ApexPages.StandardController stdController)

    asp = (Aspirant__c)stdController.getRecord(); 
}

User currentUser = [Select email from User where username = :UserInfo.getUserName() limit 1];

public  PageReference sendEmail() {
PageReference emailPage = new PageReference('/email/author/emailauthor.jsp');
Map<String, String> params = emailPage.getParameters();
params.put('p2_lkid',asp.Email__c);
params.put('p3_lkid',asp.ID); 
params.put('template_id','00X3K000000F91e'); 
params.put('rtype','003');
params.put('p24',currentUser.Email); 
params.put('new_template','1'); 
params.put('retURL',ApexPages.currentPage().getUrl()); 
     
return emailPage;     
}
}


Test:

@isTest 
public class emailHelperTest
{
 static testMethod void testMethod1() 
 {
 Aspirant__c testAsp = new Aspirant__c();
 testAsp.First_Name__c='Test' ;
 testAsp.Email__c ='tharanginigts@gmail.com';
 insert  testAsp;
 
 Test.startTest();
PageReference emailPage = new PageReference('/email/author/emailauthor.jsp');
Map<String, String> params = emailPage.getParameters();
params.put('p3_lkid',testAsp.ID); //email will be attached to the activity history of the account where the button was clicked using the acct.ID
params.put('template_id','00X3K000000F91e'); /// template ID of the email template to be shown goes here
params.put('rtype','003');
params.put('p24',testAsp.Email__c); //currentUser.Email showing in "Additional to" field
params.put('new_template','1'); 
params.put('retURL',ApexPages.currentPage().getUrl()); //after send button is clicked, go back to the account where the button was clicked
 Test.stopTest();
 }
}
Virendra ChouhanVirendra Chouhan

Hello,

This is not a correct way to write a test class.

Test class is basically used to run your code with test data. so that we know that our code is working as expected or not. In your test class you need to create testdata and then call your main method. for an example:

 Aspirant__c testAsp = new Aspirant__c();
 testAsp.First_Name__c='Test' ;
 testAsp.Email__c ='tharanginigts@gmail.com';
 insert  testAsp;
Test.StartTest(); 
			ApexPages.StandardController sc = new ApexPages.StandardController(testAsp);
			emailHelper emailHelperObj = new emailHelper(sc);
			emailHelperObj.sendEmail();
			
Test.StopTest();