HTTP server for unit tests in Delphi

前提是你 提交于 2019-12-10 03:49:06

问题


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.


回答1:


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).




回答2:


You may use unit test / DUnit to construct automatic integration tests. Say, you HTTP components as http client make calls to a Web service. You may make your own mock Web service, or just use any public Web service, like one of those from Google or Amazon. So you just need to create a Google or Amazon developer account, and consume some basic service functions for testing.




回答3:


If you're testing SOAP services, use SoapUI to stand up a "mock" service based on your WSDL. You can have it return a variety of responses (either sequentially, or use some simple scripting to match responses to the request contents.) I've done this by matching the "request ID" (just a GUID) in my request sent from the DUnit test, to a response in the SoapUI. It's a simple xpath query to match them up.

You can have it return "canned" errors/exceptions, and of course when it's not running, you'll have the "nobody's home" test case.



来源:https://stackoverflow.com/questions/9463011/http-server-for-unit-tests-in-delphi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!