Skip to main content
This guide covers testing ASP.NET Core APIs running on .NET 8 or later.
If you’re using ASP.NET Web API 2 on .NET Framework, see the ASP.NET Classic testing guide instead.
Breakdance provides a powerful test base class that wraps ASP.NET Core’s TestServer, giving you in-memory HTTP testing with full dependency injection support.

Prerequisites

1

Install the package

Add the Breakdance AspNetCore package to your test project:
2

Reference your API project

Your test project needs a reference to the project containing your controllers:

Quick Start

Inherit from AspNetCoreBreakdanceTestBase to get automatic TestServer management:
MyApiTests.cs

Configuration Methods

AspNetCoreBreakdanceTestBase provides several helper methods to configure your test environment:

AddApis()

Configures the test server with controller support (authorization, CORS, data annotations, formatter mappings):
This is equivalent to calling services.AddControllers() in your Startup.cs.

AddMinimalMvc()

Registers only the minimum MVC services needed to route requests and invoke controllers:
Use this for lightweight tests where you don’t need the full controller feature set.

AddViews()

Configures support for controllers with Razor views:

AddRazorPages()

Configures support for Razor Pages:

Custom Configuration

For more control, configure the TestHostBuilder directly:

Getting an HttpClient

Use GetHttpClient() to get a client connected to the in-memory test server:

Custom Route Prefix

Override the default route prefix:

With Authentication

Add authentication headers:

Accessing Services

Resolve services from the test server’s dependency injection container:
For .NET 8+, keyed services are also supported:

Testing POST/PUT/PATCH Requests

Testing Error Responses

Using Static Helpers

For simpler scenarios, use AspNetCoreTestHelpers without inheriting from the test base:

Integration with FluentAssertions

Combine with FluentAssertions for more expressive tests:

Comparison: TestServer vs Real Server

AspectTestServer (In-Memory)Real Server
SpeedFast (no network)Slower (HTTP overhead)
Port conflictsNonePossible
Full HTTP stackMost featuresYes
SSL testingLimitedYes
MiddlewareFull supportFull support
AuthenticationConfigurableFull support
Best forUnit tests, CI/CDE2E tests

Lifecycle

Understanding the test lifecycle helps avoid common issues:

ASP.NET Classic Testing

Test ASP.NET Web API 2 on .NET Framework

Response Snapshots

Capture and replay HTTP responses for deterministic tests