---
title: "HTTPSimulator - Simulating HTTP Requests for unit testing made easier"
url: "https://osherove.com/blog/2007/6/20/httpsimulator-simulating-http-requests-for-unit-testing-made.md"
canonical: "https://osherove.com/blog/2007/6/20/httpsimulator-simulating-http-requests-for-unit-testing-made.html"
published: "2007-06-20T13:20:40"
updated: "2007-06-20T13:20:40"
tags: [".NET", "Agile", "Agile Related", "Unit Testing"]
author: "Roy Osherove"
description: "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…"
usage: "Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page)."
license: "https://creativecommons.org/licenses/by/4.0/"
---

# HTTPSimulator - Simulating HTTP Requests for unit testing made easier

By Roy Osherove June 20, 2007 In [.NET](https://osherove.com/blog/category/net), [Agile](https://osherove.com/blog/category/agile), [Agile Related](https://osherove.com/blog/category/agile-related), [Unit Testing](https://osherove.com/blog/category/unit-testing)

**Historical article** · Originally published June 20, 2007; technical details may be outdated.

Phill Haack just [released HTTPSimulator](http://haacked.com/archive/2007/06/19/unit-tests-web-code-without-a-web-server-using-httpsimulator.aspx) - 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](http://www.dotnetkicks.com/unittesting/Unit_Test_Web_Code_Without_A_Web_Server_Using_HttpSimulator)\]

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](http://weblogs.asp.net/rosherove/archive/2007/02/25/why-you-should-think-about-ootp-object-oriented-testable-programming.aspx) ([TOOD](http://weblogs.asp.net/rosherove/archive/2007/02/25/why-you-should-think-about-ootp-object-oriented-testable-programming.aspx)) 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.

## More in .NET

[All posts in .NET](https://osherove.com/blog/category/net)

- Jun 29, 2007

    ### [Israeli .NET Bloggers Update](https://osherove.com/blog/2007/6/29/israeli-net-bloggers-update.html)

- Jun 21, 2007

    ### [Blow to open source on VS.NET: VSIP License forbids Open Source](https://osherove.com/blog/2007/6/21/blow-to-open-source-on-vsnet-vsip-license-forbids-open-sourc.html)

- Jun 5, 2007

    ### [Running Matlab, Python and Tcl scripts from .NET](https://osherove.com/blog/2007/6/5/running-matlab-python-and-tcl-scripts-from-net.html)

- May 19, 2007

    ### [Easier Winform UI Thread Safe Methods with DynamicProxy2 and Osherove.SimpleInterception](https://osherove.com/blog/2007/5/19/easier-winform-ui-thread-safe-methods-with-dynamicproxy2-and.html)


---

## About the author

**Roy Osherove**: Senior Solutions Architect at AWS working on AI for production and AI-driven development; author of The Art of Unit Testing and Elastic Leadership, with about 20 years of consulting and training on unit testing, TDD, team leadership and continuous delivery.

### Sites

- [RobotPaper](https://robotpaper.ai/): This blog: AI patterns and anti-patterns, AI and coding agents, and engineering leadership.
- [osherove.com](https://osherove.com): Roy's personal site. Author of The Art of Unit Testing and Elastic Leadership; consulting and training on unit testing, TDD, team leadership and continuous delivery, plus about 20 years of blog posts.
- [The Art of Unit Testing](https://www.artofunittesting.com): The Art of Unit Testing, 3rd Edition (Manning): readable, maintainable, trustworthy unit tests, plus TDD workshops in C#, JavaScript, Java and Kotlin.
- [5whys.com](https://www.5whys.com): Roy's writing on software team leadership: self-organizing teams, surviving chaos, learning mode and the Elastic Leadership model.
- [Pipeline Driven](https://pipelinedriven.org): Continuous delivery and DevOps practices: build patterns, pipeline-friendly testing, DevOps metrics and enterprise DevOps.
- [Elastic Leadership](https://www.elasticleadership.com): Elastic Leadership, Roy's framework for software team leaders (survival, learning and self-organizing modes).

### Social

- X: https://x.com/royosherove
- LinkedIn: https://www.linkedin.com/in/osherove/

### Contact

- Contact form: https://forms.gle/jQSx5KoXvrVA1JCK7

### License

Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page). License: https://creativecommons.org/licenses/by/4.0/
