Skip to main content
1 of 2
Cuban coffee
  • 1.6k
  • 1
  • 27
  • 57

Unit test - testing emails

I need to create a unit test class that will check if an ongoing email is having set the bcc and the cc, and also if the subject has been set.

I know I can get some details from the emails, as follows:

Messaging.SingleEmailMessage mail =  new Messaging.SingleEmailMessage()

Messaging.sendEmail(new Messaging.SingleEmailMessage[]{
                mail
});

mail.getSubject()
mail.getHTMLBody()

This is the only solution I know but it is ugly as I will need to change an already working project(the one I am testing) to check these values and put some System.assert(), so testing stuff will be out of the Unit test class.

My question is there any other better way I can proceed with these checks on the same very unit test class?

I hope my question is clear.

Thank you in advance.

Cuban coffee
  • 1.6k
  • 1
  • 27
  • 57