If you’re using ASP.NET Core (running on .NET 6+), see the ASP.NET Core testing guide instead.
Prerequisites
1
Install the package
Add the Breakdance WebApi package to your test project:
2
Reference your Web API project
Your test project needs a reference to the project containing your controllers:
Quick Start
The simplest approach usesWebApiTestHelpers to get a fully configured HttpClient:
MyApiTests.cs
How It Works
When you callGetTestableHttpClient(), Breakdance creates:
- An
HttpConfigurationwith attribute routing enabled - An
HttpServerthat processes requests in-memory - An
HttpClientconnected to that server
Configuration Options
Custom HttpConfiguration
If your API requires specific configuration (like custom routes or services), use the extension methods onHttpConfiguration:
Changing the Route Prefix
The default route prefix isapi/test. Override it to match your API’s routes:
Custom Host
Iflocalhost conflicts with something on your machine:
Sending Request Bodies
For POST, PUT, and PATCH requests, pass a payload object:Reading Response Content
Testing Error Responses
In-memory testing surfaces the same error responses your API would return in production:Because
IncludeErrorDetailPolicy.Always is set, you’ll get detailed error messages in the response body.
This is helpful for debugging test failures but should not be enabled in production.Comparison: In-Memory vs Real Server Testing
Limitations
TheBreakdance.WebApi package is specifically for ASP.NET Web API 2 on .NET Framework. It does not support:
- ASP.NET Core applications (use Breakdance.AspNetCore instead)
- OWIN/Katana middleware
- SignalR
Related Resources
ASP.NET Core Testing
Test ASP.NET Core APIs with TestServer
Response Snapshots
Capture and replay HTTP responses for deterministic tests