javaemailjunit

Junit: unit test 'receive' email feature


There's a Java application which sends out email notifications which is triggered by user updates on UI. I am trying to write JUnit test case to verify whether email has been sent out successfully by looking for ways to receive the message.

Dumbster did not work for me because, it is meant to send email and receive mail in the test program itself.

How do I test this feature? Thanks a ton for your help.

-Vadiraj.


Solution

  • First of all, sounds like your talking about an integration test, rather than a unit test.

    One time setup:

    It would be hard to automate these steps as google uses robot detection.

    Test case:

    There are some good java-imap libraries around which makes the gmail interrogation quite easy. Here is what a quick search revealed:

    http://harikrishnan83.wordpress.com/2009/01/24/access-gmail-with-imap-using-java-mail-api/