PHPUnit email testing
I have a PHPUnit test that does the following:
- fill out a form on a web page using Selenium RC
- (The app sends an email to a gmail account)
- connec开发者_Python百科t to the gmail account with imap_open()
- verify that certain strings exist in the email
My problem is that my test is failing randomly because I'm not waiting for the email to be sent. What would you do in this situation?
Don't use an external mailserver. Set up fakemail. The Python version is easier to use. http://fakemail.sourceforge.net/
I've used fakemail for quite some time and it makes my php simpletest tests run very fast (no external latency), and they're 100% repeatable.
I retain a different set of tests if I want to actually test the mail sending part of my script. In my eyes, the 'checking that strings are there' and 'checking that email got sent to gmail' are two different failure points, and should be split into different tests.
You could also "check" for the email by parsing the RSS feed of a test Gmail account:
http://www.internoetics.com/2012/08/08/create-a-gmail-rss-feed/
精彩评论