How to Unit Test Sending Mail in Apex

I ran into an issue the other day where I wanted to send out an email notification as part of a trigger. The code itself was no problem but, like most days, my problems began as I tried to write the unit test. I couldn't get the required test coverage on those lines of code.

Please, provide some better documentation on writing test cases. Unit tests are mandatory to deploy Apex to production but the documentation on unit testing is extremely lacking. Everyone on the message boards are screaming this lack of support.

I contacted our support development rep and he suggested moving the mail functions into their own class and then pass the required parameters to send the mail. This is what I came up with:

public class MailerUtils {

 public static void sendMail(string message) {

  Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
  String[] toAddresses = new String[] {'',''};

  mail.setSubject('My Subject');


  // Send the email
  Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });


 public static testMethod void testSendMail() {
  sendMail('This is my email message');


Here is a trigger that would fire after insert and send an email:

trigger TestEmail on Contact (after insert) {

  for (Contact c : {
  MailerUtils.sendMail('Welcome ' + c.Name);