Monday, December 03, 2007

Unit testing your email...

Problem: I have code which uses PEAR's mail class to send email.

Every now and then, someone breaks something rather important when doing a release. Additionally, the continuously running unit tests keep sending me email. What shall I do?

The answer, most of you are probably crying, is use a stub/mock class.

Take a look at this suggestion.

You could provide a method in the test which checks sent mail against an array of expected mail, or simply fetch the number of sent emails and check its correct.

It's come in handy in a few places on my work project; have a play and see if it comes in handy for you.

Update: this will be available in the next release.

No comments: