Search code examples
delphiunit-testinghttpdunit

HTTP server for unit tests in Delphi


I need to test some HTTP components in my Delphi app. I use DUnit and want to add some automation into testing.

So my testing code need to start the local HTTP server, configure it (for example, prepare for connection break in 3 seconds, or to simulate low bandwidth, or to ask for login/password etc), run my unit-tests and close HTTP server.

Are there some HTTP servers available exactly for Delphi/DUnit?

I know that Mozilla team have such server, but it's not too easy to integrate it into DUnit.


Solution

  • I use Indy's TIdHttpServer to serve stuff in the same process.

    This approach allows me to check that the requests coming in are correct, as well as checking the behaviour from the client end.

    Also, you can individually set up the server on a testcase by testcase basis, making your unit tests easier to understand (meaning that you don't have a piece of the 'test' somewhere else).