Skip to main content
net11.0

Support for writing functional tests for MVC applications. This package was built from the source code at https://github.com/dotnet/dotnet/tree/3551975be08744f0418857c5bed8ab1545c5dd47

Published
Sep 8, 2026
1mo ago
Total Downloads
402.1M
402,052,960

Install

dotnet add package Microsoft.AspNetCore.Mvc.Testing --version 11.0.0-rc.1.26425.128
ProductVersions
.NET
net11.0

README

About

Microsoft.AspNetCore.Mvc.Testing provides support for writing integration tests for ASP.NET Core apps that utilize MVC or Minimal APIs.

Key Features

  • Copies the dependencies file (.deps.json) from the System Under Test (SUT) into the test project's bin directory
  • Sets the content root to the SUT's project root so that static files are found during test execution
  • Provides the WebApplicationFactory class to streamline bootstrapping the SUT with TestServer

How to Use

To use Microsoft.AspNetCore.Mvc.Testing, follow these steps:

Installation

To install the package, run the following command from the directory containing the test project file:

dotnet add package Microsoft.AspNetCore.Mvc.Testing

Configuration

To configure the test app, follow these steps:

  1. Specify the Web SDK in the test project file (<Project Sdk="Microsoft.NET.Sdk.Web">).
  2. Add references to the following packages:
    • xunit
    • xunit.runner.visualstudio
    • Microsoft.NET.Test.Sdk
  3. Add a test class to the test project:
    public class BasicTests
        : IClassFixture<WebApplicationFactory<Program>>
    {
        private readonly WebApplicationFactory<Program> _factory;
    
        public BasicTests(WebApplicationFactory<Program> factory)
        {
            _factory = factory;
        }
    
        [Theory]
        [InlineData("/")]
        [InlineData("/Index")]
        [InlineData("/About")]
        [InlineData("/Privacy")]
        [InlineData("/Contact")]
        public async Task Get_EndpointsReturnSuccessAndCorrectContentType(string url)
        {
            // Arrange
            var client = _factory.CreateClient();
    
            // Act
            var response = await client.GetAsync(url);
    
            // Assert
            response.EnsureSuccessStatusCode(); // Status Code 200-299
            Assert.Equal("text/html; charset=utf-8",
                response.Content.Headers.ContentType.ToString());
        }
    }
    

Additional Documentation

For additional documentation and examples, refer to the official documentation on integration testing in ASP.NET Core.

Feedback & Contributing

Microsoft.AspNetCore.Mvc.Testing is released as open-source under the MIT license. Bug reports and contributions are welcome at the GitHub repository.

Changes from Previous Version

No structural changes between v11.0.0-preview.7.26381.103 and v11.0.0-rc.1.26425.128.

Adoption Assessment

API and MVC apps that need realistic middleware, routing and dependency injection coverage without external process orchestration.

Integration Testing Guide
This version is marked prerelease. Validate its API and upgrade path before production use.Compatibility metadata lists 1 target framework; confirm the exact target used by your application.
Editorial Note: Bootstraps ASP.NET Core applications in tests via TestServer/WebApplicationFactory for high-fidelity HTTP integration tests. Trade-off: External dependencies still need explicit test doubles or infrastructure provisioning to avoid false confidence.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.