Follow @RoyOsherove on Twitter

HTTPSimulator - Simulating HTTP Requests for unit testing made easier

Phill Haack just released HTTPSimulator - a class to help with running tests against a simulated Http Context, to help simulate requests and more without resorting to needing a web server running for the tests. [via DNK]

I like this approach but I also like Phil's comments at the end. Read them. He's right.

Also noted:

"originally tried to do all this by using the public APIs. Unfortunately, so many classes are internal or sealed that I had to get my hands dirty and resort to using reflection. Doing so freed me up to finally get certain features working that I could not before."

This again goes to the Testable Object Oriented Design (TOOD) idea that I wrote about. Testable design might mean two categories:

  • A Test Enableing\Disabling design (Sealed classes, high coupling etc. is preventing us from writing tests that simulate or stub out parts of the design)
  • A testable\non testable design - meaning you can easily or not easily test the parts in the code you'd like to test.

In this case the HTTP related classes are test-disablers in that we cannot easily stub out their features to test something that relies on them.

Blow to open source on VS.NET: VSIP License forbids Open Source

Art Of Unit Testing Book Available Shortly