commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex Chaffee / Purple Technology <g...@stinky.com>
Subject Re: Ideas for testing commons-mail
Date Sun, 09 Mar 2003 21:05:14 GMT

On Sun, Mar 09, 2003 at 02:17:29PM -0600, Quinton McCombs wrote:
> I have been developing some unit tests for commons-mail.  The problem is
> that the only way that I have to test is to actually send an email and
> inspect it manually.  Has anyone else ever tested something like this
> before without having to go through the manual inspection?


Yes.  My open-source XP project Calliope has a "mock SMTP server",
originally written by William Pietri and myself.  A unit test will
spawn one of these guys on port 2525, then tell the object under test
that its outbound SMTP server is localhost:2525, then check the
message that was sent to it.

Another option is to refactor the mail sending code so it talks SMTP
to an inputstream and an outputstream, rather than directly to a
socket.  You then unit test against these streams (passing in
ByteArrayOuputStream and the like).  We have code for this scenario
too.

http://sf.net/projects/calliope
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/calliope/calliope/test/src/calliope/

look for MajordomoMessengerTest, NetworkSmtpServer[Test],
SmtpConversation[Test], and StreamedSmtpConversation (and possibly
other related files).

Feel free to incorporate the code into commons (it's a BSD license, so
just giving credit to Calliope somewhere should suffice).  It was
written test-first to meet our needs, so it's pretty raw, but suffices
for the simple case.  If you make any changes (like allowing it to
handle multiple messages per connection) please let us know.

 - A

-- 
Alex Chaffee                               mailto:alex@jguru.com
Purple Technology - Code and Consulting    http://www.purpletech.com/
jGuru - Java News and FAQs                 http://www.jguru.com/alex/
Gamelan - the Original Java site           http://www.gamelan.com/
Stinky - Art and Angst                     http://www.stinky.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message