Skip to content

Instantly share code, notes, and snippets.

@techb
Created June 17, 2020 13:38
Show Gist options
  • Save techb/85181dfe5e420b3ba2dc43e6c8153cd6 to your computer and use it in GitHub Desktop.
Save techb/85181dfe5e420b3ba2dc43e6c8153cd6 to your computer and use it in GitHub Desktop.
Unit test for sending emails in Apex
@isTest
public class TestEmailSend {
@isTest
static void testTheEmail(){
Test.startTest();
// the method we're testing
// https://gist.github.com/techb/7519e95bac3caa2b8adb3f65d2dc2dc8
EmailSend.sendEmail('test@test.com');
// we assert buy what govener limits say
Integer invocations = Limits.getEmailInvocations();
Test.stopTest();
System.assertEquals(1, invocations, 'Email has not been sent');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment