Friday, 18 May 2007

Mock JavaMail rocks. Mocking out protocols and services is damn useful

If ever you find yourself needing to test some JavaMail code, I highly recommend Mock JavaMail. It does exactly what it says on the tin & is very useful. Its yet another project from the incredibly prolific Kohsuke - nice job! We're using Mock JavaMail on Camel to test our Mail Integration and its been soo useful.

All APIs to messaging & integration systems and protocols should have some Mock testing library to allow developers to create easy unit tests and to save them having to mock complex services (which you're never sure your mocks are faithful to the underlying systems & protocols).

For JMS we can use ActiveMQ. For Camel and JBI we have Mock Endpoints (which I wish we had years ago, it'd have made developing ServiceMix much easier). For files you can just use your local file system; for databases you can use Derby, HSQLDB or H2. For HTTP/REST you can just embed Jetty.

I guess the missing things are things like XMPP and FTP. Anyone seen any other interesting mock projects for specific protocols, APIs and services? (Yes I know about jMock :)

4 comments:

berndf said...

Hi James, currently I am bootstrapping a XMPP server project at labs.apache.org. As I have a kind of TDD approach and I currently focus on delivering the stanza-level server-side protocol without dealing with the transport layer it hopefully should be possible to use it for mocking XMPP "in-process" some time soon.

James Strachan said...

Awesome! Let me know the second you have something usable; I'd love to use it in Camel

Stephan.Schmidt said...

For SMTP I've used with some success dumbster and (more recently) SubEthaSMTP Wiser.

http://subethasmtp.tigris.org/
http://quintanasoft.com/dumbster/

Unknown said...

*bump*

For mocking out FTP I can highly recommend MockFtpServer (http://mockftpserver.org). We're successfully using it when testing Camel routes.