commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex Chaffee / Purple Technology <>
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

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                     
Purple Technology - Code and Consulting
jGuru - Java News and FAQs       
Gamelan - the Original Java site 
Stinky - Art and Angst           

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message