Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to unit test an email client

I'm working on a desktop email client right now, and I want to unit test my backend. However, I can't see a way to make that work. In order for my code to work, it has to connect to a working mail server. Unless I tie my unit tests to an email account, and make sure that account matches the state my tests expect, I don't see how I can manage this.

Does anyone have any ideas on how to test this sort of application, where it relies on external factors by design?

EDIT:

To add some details: I'm working on a C++ higher level mail client library for my application, which uses libEtPan, a C library, to actually handle the details of connecting to the mail server and interacting with it.

like image 551
Matt Moriarity Avatar asked Dec 30 '22 14:12

Matt Moriarity


1 Answers

I would mock the email server, and configure that mocked object to accept/reject emails as appropriate (depending on your tests).

To do this effectively, you need an interface to talk to your email server through. For testing, the implementation is a mocked object. For deployment you substitute this with an implementation that talks directly to a mail server.

See this SO question for C++ mocking frameworks.

like image 67
Brian Agnew Avatar answered Jan 01 '23 02:01

Brian Agnew