Here is my dilemma, I have a Schedulable Class that is set up to send an email reminder on a Task. I have two solutions; (1) The Schedulable Class that includes the Messaging.SingleEmailMessage method, and (2) The Schedulable Class that does not include the Messaging.SingleEmailMessage method, but rather uses the utility MailerUtils.sendMail for the Messaging.SingleEmailMessage method.
For Solution (1) My Test Class results in 20% coverage, however, when I use both the Schedulable Class along with the MailerUtils.sendMail Class my Test Class results in 85% coverage and 100%, respectively.
Would appreciate any direction you can provide to help me solve this.
Here is my Test Class for both solutions (I have intentionally left out asserts, as it doesn't seem to effect code coverage %. I will add in asserts once I get the code coverage % needed). If asserts do help with Code Coverage % please let me know.
TEST METHOD HAS BEEN UPDATED AND NOW AT 100%
@isTest
private class TestEmailReminderClass { public static TestMethod void Test(){
String CRON_EXP = '0 0 0 15 3 ? 2022';
// Schedule the test job
String jobId = System.schedule('This is a Test',
CRON_EXP,
new TaskEmailReminder());
//Create and insert a task
Task tsks = new Task(Description = 'Task Description', Subject = 'Task Subjeck', Status = 'Not Completed', Turn_On_Email_Reminder__c = true);
insert tsks;
List<Task> listTasks = new List<Task>();
listTasks = [select id, ownerID, task.owner.name, task.owner.email, task.what.name, description, subject, activityDate, status from task where activityDate = tomorrow];
for(Task tsk : listTasks)
{
System.assertEquals(tsk.Subject, 'Task Subject');
}
MailerUtils.sendMail('test');
String message = 'This is my message';
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {'[email protected]','[email protected]'};
mail.setToAddresses(toAddresses);
mail.setSubject('My Subject');
mail.setUseSignature(false);
mail.setHtmlBody(message);
// Send the email
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
Here is Schedulable Class; Solution (1) with Code Coverage:
Here is Schedulable Class along with the MailerUtils Class; Solution (2) with Code Coverage for each class:
I basically am trying to figure out how do I combine the two to get the necessary code coverage OR is there a solution that will allow me to pass tsk.owner.email into the utility.
Thank you!