I am writing a test class for my controller that creates an email using renderStoredEmailTemplate to generate the body and subject. I am wondering if I need to somehow create an email template or should I just use if(Test.isRunningTest()) to conditionally enter a constant value for body and subject? Are the email templates visible in test mode?
-
3Have you tried it? Should be quite easy to verify either way. – Adrian Larson♦ Jun 7 '18 at 17:31
Yes, email templates are available in unit tests, so you don't need to wall off code with Test.isRunningTest. This will allow you to potentially reach 100% coverage. It also acts as a fail safe in case you accidentally forget to deploy the template, since your test should fail if the template is missing.