Unit tests for BizUnit's HTTP related steps

Mar 1, 2008 at 10:31 PM
Edited Mar 1, 2008 at 10:52 PM
I have modified BizUnit's HttpPostStep to support authentication. Before submiting my changes, I would like to write some automated unit tests for the changes. The tests would post a message to a test web server, and would ensure the post succeeds only if the user is authorized.

I have experimented with various strategies for doing these tests:
  • Have a test that expects some test code (.aspx) to be deployed in IIS. This would be similar to what the tests for SOAPHTTPRequestResponseStep do, by expecting /StockQuoteService/StockQuoteService.asmx?wsdl to be available. The problem with this strategy is that it requires some manual setup before being able to run the unit tests (and I could not find a document explaining how to do this setup)

  • Use the previous method, but add test initialization code that setups the required virtual directories, user accounts, authentication configuration, etc. This could be implemented, for example, with a MSBuild script that uses SdcTasks (Microsoft.Sdc.Tasks.Web.WebSite.CreateVirtualDirectory, etc). The problem here is that it would be hard to do a script that works for all environments. For example, if the machine has sharepoint, the test virtual directory should be excluded from sharepoint (using stsadm.exe), but this step must be skipped if it doesn't have sharepoint.

  • Instead of relying on IIS, use a web server that can be embedded within the unit tests, such as Cassini (see http://www.hanselman.com/blog/PermaLink.aspx?guid=944a5284-6b8d-4366-81e8-2e241401e1b3 for a good example). This method didn't work for me, because Cassini has no support for authentication (it could be done by modifying Cassini to add that support)

  • Don't interact with a real web server. Instead, record the expected communication between client and server, by testing manually and recording with a sniffer. Then implement a simple tcp server that simply expects a "replay" of this recorded communication, and makes the test fail if it is different.

Would you favor a specific way to implement tests for BizUnit steps that need to interact with a web server? I think the first solution (as currently done for SOAPHTTPRequestResponseStep) could be fine, as long as a "To do before running unit tests" document is available. But a fully automated solution would be even better.

I would prefer to use a strategy that's common to all BizUnit tests. If none has been established yet, I could continue investigating on possible solutions.