Dumbster: Email Testing

Introduction

The Dumbster is a very simple fake SMTP server designed for unit and system testing applications that send email messages. It responds to all standard SMTP commands but does not deliver messages to the user. The messages are stored within the Dumbster for later extraction and verification.

The Dumbster slots itself very easily into your testing strategy. As long as your application talks to an email server using SMTP then the Dumbster can be used to test the application with no code changes.

The Dumbster is useful in the following scenarios:

System testing an application. It is important at this stage of the development process that all functionality is active and not stubbed out. The Dumbster is able to respond just like a regular SMTP server but delivers no email messages to end users. This is important if you are testing with real world data. In addition it is possible to verify that the correct email messages would have been delivered to the end users by querying the Dumbster. Unit testing code that needs to send email. Again the Dumbster can be used as a dumpster to collect all email and ensure nothing is delivered to real users. In addition if the code being tested needs to deliver a specific set of email messages, with specific content then the Dumbster can be queried from within the unit test to verify correct delivery and content.

The Dumbster is written in Java and is open source. It is distributed under the Apache License 2.0.

Examples

The following is a simple example of how to unit test the email components of your application

public class SimpleSmtpServerTest extends TestCase {
...
  public void testSend() {
    SimpleSmtpServer server = SimpleSmtpServer.start();

    try {
      // Submits an email using javamail to the email server listening on port 25 
      // (method not shown here). Replace this with a call to your app logic.
      sendMessage(25, "sender@here.com", "Test", "Test Body", "receiver@there.com");
    } catch(Exception e) {
      e.printStackTrace();
      fail("Unexpected exception: "+e);
    }

    server.stop();

    assertTrue(server.getReceivedEmailSize() == 1);
    Iterator emailIter = server.getReceivedEmail();
    SmtpMessage email = (SmtpMessage)emailIter.next();
    assertTrue(email.getHeaderValue("Subject").equals("Test"));
    assertTrue(email.getBody().equals("Test Body"));    
  }
...  
}

Download

The Dumbster may be downloaded from the Dumbster SourceForge project page: http://sourceforge.net/projects/dumbster.

Documentation

The JavaDoc is here. The JavaWorld article is here.

Support

Any questions, bug fixes, suggestions should be submitted through the Dumbster forums on the SourceForge project page: http://sourceforge.net/projects/dumbster.

If you would like help with improving your unit testing strategy such as testing "untestable" parts of your code base the author is available on a freelance basis. For further information please contact me (Jason Kitchen) at the following address: consultancy@quintanasoft.com.

Donations

Donations are gratefully accepted and will be used to pay for hosting and beer in that order. They will also bump you to the top of the list for any new features you request.

Another important way you can donate is through reporting bugs, fixing bugs, and development of new features. I have a number of interesting projects for anyone interested in donating time to the project.




You are viewing a mobilized version of this site...
View original page here

Mobilized by Mowser Mowser