Microsoft.AspNetCore.Mvc.Testing (10.0.11)

Published 2026-09-09 02:35:44 +03:30 by kayer

Installation

dotnet nuget add source --name kayer --username your_username --password your_token 
dotnet add package --source kayer --version 10.0.11 Microsoft.AspNetCore.Mvc.Testing

About this package

Support for writing functional tests for MVC applications.

This package was built from the source code at e2f47b0110

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.

Dependencies

ID Version Target Framework
Microsoft.AspNetCore.TestHost 10.0.11 net10.0
Microsoft.Extensions.DependencyModel 10.0.11 net10.0
Microsoft.Extensions.Hosting 10.0.11 net10.0
Details
NuGet
2026-09-09 02:35:44 +03:30
9
Microsoft
90 KiB
Assets (2)
Versions (2) View all
10.0.11 2026-09-09
9.0.0 2026-02-20