If you’re using ASP.NET Core (running on .NET 6+), see the ASP.NET Core testing guide instead.
Prerequisites
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
| Aspect | In-Memory Testing | Real Server Testing |
|---|---|---|
| Speed | Fast (no network) | Slower (HTTP overhead) |
| Port conflicts | None | Possible |
| Full HTTP stack | No (no network layer) | Yes |
| SSL testing | No | Yes |
| Message handlers | Full support | Full support |
| Best for | Unit tests, CI/CD | Integration tests, E2E |
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