4 Testing - Reference Documentation
Authors: Grails Plugin Collective
Version: 1.0.8-SNAPSHOT
4 Testing
Typically, you don't want to actually send email as part of your automated tests. Besides wrapping all calls tosendMail
in an environment sensitive guard (which is a very bad idea), you can use one of the following techniques to deal with this.Disabling mail sending
You can effectively disable mail sending globally in your test by setting the following value in your application for the test environment.grails.mail.disabled = true
sendMail()
to be a non operation, with a warning being logged that mail is disabled. The advantage of this technique is that it is cheap. The disadvantage is that it makes it impossible to test that mail would be sent and to inspect any aspects of the sent mail.Using an override address
You can override any and all recipient email addresses insendMail()
calls to force messages to be delivered to a certain mailbox.grails.mail.overrideAddress = "test@myorg.com"
to
, cc
and bcc
addresses will be replaced by this value if set. The advantage of this mechanism is that it allows you to test using a real SMTP server. The disadvantage is that it requires a real SMTP server and makes it difficult to test address determination logic.