Where Are the Tests for ASP.NET Core Located? A Complete Directory Guide
The ASP.NET Core tests are co-located with source code under the src directory, where each framework component maintains its own test subfolder containing xUnit-based .csproj projects.
All tests for the dotnet/aspnetcore repository live alongside the implementation code rather than in a separate top-level directory. This colocated structure enables isolated component testing while supporting full solution-wide test runs via standard .NET CLI commands.
Test Directory Structure and Naming Conventions
The repository follows a consistent pattern where test projects reside in test subfolders within their respective component directories. The typical layout mirrors the source structure:
src/
├─ <Component>/
│ ├─ <Sub-module>/
│ │ ├─ test/
│ │ │ ├─ <Test Project>.csproj
│ │ │ └─ *.cs (test classes)
│ │ └─ src/ (implementation)
│ └─ ...
└─ ...
All test projects use standard xUnit frameworks and are discoverable by dotnet test. The build pipeline automatically compiles and executes these assemblies during CI runs.
Component-Level ASP.NET Core Test Locations
Each major framework area maintains dedicated test projects following the src/<Component>/test/ convention. Here are the specific locations for key components:
Hosting Tests
Functional tests for the hosting layer reside in src/Hosting/test/FunctionalTests/. The project file Microsoft.AspNetCore.Hosting.FunctionalTests.csproj contains integration tests that validate web host initialization, configuration, and lifecycle management.
SignalR Tests
Real-time communication tests are split across multiple locations:
- Core SignalR tests:
src/SignalR/server/SignalR/test/Microsoft.AspNetCore.SignalR.Tests.csproj - StackExchangeRedis backplane tests:
src/SignalR/server/StackExchangeRedis/test/Microsoft.AspNetCore.SignalR.StackExchangeRedis.Tests.csproj
These projects contain both unit tests for hub routing and integration tests for scale-out providers.
Routing Tests
The routing middleware maintains separate test assemblies for different testing levels:
- Unit tests:
src/Http/Routing/test/UnitTests/Microsoft.AspNetCore.Routing.Tests.csproj - Functional tests:
src/Http/Routing/test/FunctionalTests/Microsoft.AspNetCore.Routing.FunctionalTests.csproj
This separation allows developers to run fast unit tests independently from slower integration scenarios.
HTTP Abstractions and Middleware Tests
Core HTTP functionality tests live in src/Http/Http/test/Microsoft.AspNetCore.Http.Tests.csproj, validating HttpContext, HttpRequest, and HttpResponse implementations.
Additional Component Test Locations
- WebEncoders:
src/WebEncoders/test/Microsoft.Extensions.WebEncoders.Tests.csproj - Logging.AzureAppServices:
src/Logging.AzureAppServices/test/Microsoft.Extensions.Logging.AzureAppServices.Tests.csproj - DataProtection:
src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/Microsoft.AspNetCore.DataProtection.Tests.csproj - Components (Blazor WebAssembly):
src/Components/WebAssembly/WebAssembly/test/Microsoft.AspNetCore.Components.WebAssembly.Tests.csproj
Infrastructure and Shared Testing Framework
Beyond component-specific tests, the repository includes base testing utilities in src/Testing/test/. The project Microsoft.AspNetCore.InternalTesting.Tests.csproj provides custom xUnit attributes, test base classes, and helper utilities used across the entire test suite.
This infrastructure project contains the foundational TestableAssembly classes and shared assertions that component tests inherit.
Practical Example: Routing Unit Test
Tests follow standard xUnit patterns with [Fact] attributes. Here is a representative example from the Routing component:
using Microsoft.AspNetCore.Routing;
using Xunit;
public class SimpleRouteTests
{
[Fact]
public void RouteMatcher_IgnoresTrailingSlash()
{
var route = new RoutePatternParser().Parse("/home/");
var matcher = new DefaultRouter();
var result = matcher.Match("/home", route);
Assert.True(result.IsMatch);
}
}
This test file would reside at src/Http/Routing/test/UnitTests/SimpleRouteTests.cs according to the repository structure.
How to Run ASP.NET Core Tests Locally
Execute the entire test suite from the repository root:
dotnet test src/
Run tests for a specific component only:
dotnet test src/Hosting/test/FunctionalTests/
Filter by fully qualified test name:
dotnet test --filter "FullyQualifiedName~Microsoft.AspNetCore.Routing.Tests"
Summary
- ASP.NET Core tests are located in
testsubfolders within each component directory undersrc/ - Hosting tests reside in
src/Hosting/test/FunctionalTests/ - SignalR tests are found in
src/SignalR/server/SignalR/test/and related subdirectories - Routing tests split between
src/Http/Routing/test/UnitTests/andFunctionalTests/ - Infrastructure tests for shared utilities live in
src/Testing/test/ - All projects use xUnit and support standard
dotnet testcommands
Frequently Asked Questions
What testing framework does ASP.NET Core use?
ASP.NET Core uses xUnit.net as its primary testing framework. All test projects reference xUnit packages and use standard [Fact] and [Theory] attributes for test methods, as implemented in the dotnet/aspnetcore repository.
How do I run only specific component tests?
Navigate to the specific test project directory or provide the path to dotnet test. For example, run dotnet test src/SignalR/server/SignalR/test/ to execute only SignalR tests, or use the --filter option with namespace patterns to target specific areas without changing directories.
Are there integration tests or only unit tests?
The repository contains both unit and integration tests. Components like Routing and Hosting maintain separate UnitTests and FunctionalTests directories. Functional tests validate end-to-end scenarios with actual HTTP requests, while unit tests isolate individual classes and methods.
Where are the Blazor and WebAssembly tests located?
Blazor WebAssembly-specific tests are located in src/Components/WebAssembly/WebAssembly/test/Microsoft.AspNetCore.Components.WebAssembly.Tests.csproj. Additional Razor Components tests are spread throughout the src/Components/ tree, following the same test subfolder convention as other ASP.NET Core components.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →