I want to unit test a Java application that fetches mails from an email inbox, much like this guy. Currently, I run the unit tests against a real mailbox on our company's real mailserver which was easy to set up, but has the following disadvantages:
- You have to send actual emails before you run the test
- Adding more test cases might be difficult, for example because you might want to test against different security policies
- The test depends on a working network connection to the mail server and an existing mail account which couples development and system administration in a way that makes no sense to me.
I would like to fire up an IMAP server on a local port, which fakes an inbox based on test data stored in files alongside the test classes. I can think of the following approaches:
- Run a socket server and implement a rudimentary IMAP subset
- Use a higher level library made for building email servers
- Use an existing email server implementation that I can embed in my tests
I would like to avoid the first option, it sort of looks straightforward, but I'm guessing from similar experience that there's a long tail of work waiting further down the road. Just think of wanting to test secure connections etc. Similarly, the second option seems like to much work, but I haven't found a mail server yet that would allow for the third one.
If it matters, I'm using Maven and TestNG during the build process.