SkillAgentSearch skills...

MyTested.AspNetCore.Mvc

Fluent testing library for ASP.NET Core MVC.

Install / Use

/learn @ivaylokenov/MyTested.AspNetCore.Mvc

README

<h1><img src="https://raw.githubusercontent.com/ivaylokenov/MyTested.AspNetCore.Mvc/master/tools/logo.png" align="left" alt="MyTested.AspNetCore.Mvc" width="100">&nbsp; MyTested.AspNetCore.Mvc - Fluent Testing<br />&nbsp; Library for ASP.NET Core MVC</h1>

Diamond Sponsors

<table> <tbody> <tr> <td align="center" valign="middle"> <a href="http://bit.ly/3da6h7f" target="_blank"> <img width="323px" src="https://user-images.githubusercontent.com/3391906/77253785-5b734880-6c65-11ea-92d5-71dcfc833fe0.png"> </a> </td> </tr> </tbody> </table>

Gold Sponsors

<table> <tbody> <tr> <td align="center" valign="middle"> <a href="https://softuni.org/" target="_blank"> <img width="148px" src="https://softuni.foundation/wp-content/uploads/2017/08/SoftUni_Foundation_Logo_Oneline-1.png"> </a> </td> <td align="center" valign="middle"> <a href="http://bit.ly/30xsnsC" target="_blank"> <img width="148px" src="https://user-images.githubusercontent.com/3391906/65251792-dd848800-daef-11e9-8857-637a48048cda.png"> </a> </td> </tr> </tbody> </table>

Special Sponsors

<table> <tbody> <tr> <td align="center" valign="middle"> <a href="http://bit.ly/bellatrixsolutions" target="_blank"> <img width="120px" src="https://user-images.githubusercontent.com/3391906/68993273-d4f5c700-087e-11ea-9b39-e173733fcbfb.png" alt="The Ultimate Cross-Platform .NET Framework"> </a> </td> <td align="center" valign="middle"> <a href="https://www.jetbrains.com/?from=MyTestedASP.NET" target="_blank"> <img width="120px" src="https://user-images.githubusercontent.com/3391906/72542498-ee21f080-388c-11ea-92ac-0b0153028933.png" alt="JetBrains"> </a> </td> </tr> </tbody> </table>

Project Description

MyTested.AspNetCore.Mvc is a strongly-typed unit testing library providing an easy fluent interface to test the ASP.NET Core framework, perfectly suitable for both MVC and API scenarios. It is testing framework agnostic so that you can combine it with a test runner of your choice (e.g. xUnit, NUnit, etc.).

Windows: Build status

Ubuntu & Mac OS: Build Status

Downloads: NuGet Badge

<img src="https://raw.githubusercontent.com/ivaylokenov/MyTested.AspNetCore.Mvc/version-3.1/tools/test-sample.gif" />

MyTested.AspNetCore.Mvc has more than 500 assertion methods and is 100% covered by more than 2500 unit tests. It should work correctly. Almost all items in the issues page are expected future features and enhancements.

MyTested.AspNetCore.Mvc helps you speed up the testing process in your web development team! If you find that statement unbelievable, these are the words which some of the many happy MyTested.AspNetCore.Mvc users once said:

"I’ve been using your packages for almost 3 years now and it has saved me countless hours in creating unit tests and wanted to thank you for making this. I cannot imagine how much code I would have had to write to create the 450+ and counting unit tests I have for my controllers."

"I absolutely love this library and it greatly improved the unit/integration test experience in my team."

"Amazing library, makes you want to do test-driven development, thanks!"

"Wanted to thank you for your effort and time required to create this. This is a great tool! Keep up the good work."

Take a look around and...

⭐️ ...if you like the library, star the repository and show it to your friends!

😏 ...if you find it useful, make sure you subscribe for future releases by clicking the "Watch" button and choosing "Releases only"!

👀 ...if you want to learn cool C# coding techniques, subscribe to my YouTube channel, where I regularly post online video lessons!

✔ ...if you want to support the project, become a sponsor/backer!

Featured in

Sponsors & Backers

MyTested.AspNetCore.Mvc is a community-driven open source library. It's an independent project with its ongoing development made possible thanks to the support by all my awesome backers. If you'd like to join them, please consider:

What's the difference between Patreon and OpenCollective?

Funds donated via both platforms are used for development and marketing purposes. Funds donated via OpenCollective are managed with transparent expenses. Your name/logo will receive proper recognition and exposure by donating on either platform.

Additionally, funds donated via Patreon give me the freedom to continue the library development.

Main Features

  • Built-in service mock resolver - register your mocks once, use them everywhere.
  • Full request setup - excellent arrangement of fake request data.
  • Detailed response assertions - precise validation for all available result objects.
  • Controller tests - unit or integration tests for both MVC and API scenarios.
  • View component tests - validate your view logic as fast as possible.
  • Route tests - asserting route paths and model binding is as accessible as it can get.
  • Pipeline tests - from the web request to the returned response - the whole chain is validated.
  • Simple and easy to learn fluent API - takes no more than 20 minutes to learn the library.
  • Strongly-typed assertions - the fluent test chain is designed to be developer-friendly and helpful.
  • Friendly error messages - failed tests throw exceptions with detailed error reports.
  • Isolated test scope - each test is run in isolated scope, making asynchronous execution more than welcome.
  • Built-in mocks - in-memory database, authentication, authorization, session, caching, temp data, and more.

Quick Start

This quick start is for ASP.NET Core 3.1. For previous versions, check the corresponding branches.

To add MyTested.AspNetCore.Mvc to your solution, you must follow these simple steps:

  1. Create a test project.
  2. Reference your web application.
  3. Install MyTested.AspNetCore.Mvc.Universe (or just the testing packages you need) from NuGet.
  4. Create a testsettings.json file at the root of the test project, set its Copy to Output Directory property to Copy if newer, and set your required application settings to fake ones:
{
  "ConnectionStrings": {
    "DefaultConnection": "My Fake Connection String"
  },
  "AllowedHosts": "*"
}
  1. Your test project's .csproj file should be similar to this one:
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <None Update="testsettings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>
	
  <ItemGroup>
    <PackageReference Include="MyTested.AspNetCore.Mvc.Universe" Version="3.1.1" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
    <PackageReference Include="xunit" Version="2.4.1" /> <!-- Can be any testing framework --> 
    <PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\MyApp\MyApp.csproj" /> <!-- Reference to your web project --> 
  </ItemGroup>

</Project>
  1. Create a TestStartup class at the root of the test project to register the dependency injection services, which will be used by all test cases in the assembly. A quick solution is to inherit from the web project's Startup class. By default MyTested.AspNetCore.Mvc replaces all ASP.NET Core services with ready to be used mocks. You only need to replace your own custom services with mocked ones by using the provided extension methods.
namespace MyApp.Tests
{
 
View on GitHub
GitHub Stars1.7k
CategoryDevelopment
Updated8d ago
Forks178

Languages

C#

Security Score

85/100

Audited on Mar 13, 2026

No findings