MSTestEnhancer 1.2.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package MSTestEnhancer --version 1.2.1
NuGet\Install-Package MSTestEnhancer -Version 1.2.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MSTestEnhancer" Version="1.2.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MSTestEnhancer --version 1.2.1
#r "nuget: MSTestEnhancer, 1.2.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install MSTestEnhancer as a Cake Addin
#addin nuget:?package=MSTestEnhancer&version=1.2.1

// Install MSTestEnhancer as a Cake Tool
#tool nuget:?package=MSTestEnhancer&version=1.2.1

English | 简体中文 | 繁體中文

MSTest Enhancer

MSTestEnhancer is a MSTest v2 extension to connect unit test and the method that should be tested. You'll find out that all unit test contracts are listed under target methods, and you can see all the result of them directly, no need to translate the obscure method name into what you want to test.

Getting Started

  1. Install MSTestEnhancer from the nuget.org.
  2. Write unit test code in the style listed below.

Assuming that you want to test a class named TheTestedClass containing a method named TheTestedMethod. Then you can write unit tests like this:

[TestClass]
public class TheTestedClassTest
{
    [ContractTestCase]
    public void TheTestedMethod()
    {
        "When Xxx happens, results in Yyy.".Test(() =>
        {
            // Write test case code here...
        });
        
        "When Zzz happens, results in Www.".Test(() =>
        {
            // Write test case code here...
        });
    }
}

Notice that the name of class and method are almost the name of the tested class and tested method. As a result, we don't need to think about anything about naming unit test, nor to read the obscure name of the unit test.

Test results

Unit Test with Arguments

Some unit tests need multiple values to verify the contracts, so MSTestEnhancer provides WithArguments method to config the arguments.

"prime number.".Test((int num) =>
{
    // Write test case code here...
}).WithArguments(2, 3, 5, 7, 11);

"{0} is not a prime number.".Test((int num) =>
{
    // Write test case code here...
}).WithArguments(1, 4);

You can pass up to 8 parameters into the test case.

"Contract 1: {0} and {1} are allowed in the contract description.".Test((int a, int b) =>
{
    // Now, a is 2 and b is 3.
}).WithArguments(2, 3);

"Contract 2".Test((int a, int b) =>
{
    // Now the test case will run twice. The first group, a is 2 and b is 3; and the second group, a is 10 and b is 20.
    // ValueTuple is supported, too.
}).WithArguments((2, 3), (10, 20));

In this example, the contract description will be replaced to the arguments that you have passed into.

Async Unit Test

All Test extension method support async action so that you can test any async method.

Some Fantastic Feature

Nested unit test classes are supported by MSTest v2, so you can write an infinite level unit test tree.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 is compatible.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on MSTestEnhancer:

Package Downloads
dotnetCampus.UITest.WPF

The UITest framework for WPF

GitHub repositories (3)

Showing the top 3 popular GitHub repositories that depend on MSTestEnhancer:

Repository Stars
dotnet-campus/AsyncWorkerCollection
高性能的多线程异步工具库。A collection of tools that support asynchronous methods and support high-performance multithreading.
lindexi/lindexi_gd
博客用到的代码
dotnet-campus/dotnetCampus.Ipc
本机内多进程通讯库
Version Downloads Last updated
2.2.1 1,145 10/27/2022
2.2.1-alpha01 1,370 2/21/2022
2.2.0 3,173 1/6/2022
2.1.2-alpha03 173 12/27/2021
2.1.2-alpha02 166 12/27/2021
2.1.2-alpha01 137 12/27/2021
2.1.1 1,036 8/4/2021
2.1.1-alpha02 201 8/4/2021
2.1.1-alpha01 246 8/4/2021
2.1.0 3,456 3/4/2021
2.0.2-alpha03 109 8/10/2023
2.0.2-alpha02 121 4/18/2023
2.0.1 4,400 5/24/2020
1.6.0 3,097 6/21/2018
1.4.0 1,268 3/20/2018
1.3.0 916 2/26/2018
1.2.1 885 2/24/2018
1.2.0 883 2/13/2018
1.1.0 900 2/12/2018
1.0.0 910 2/11/2018

Extract the inner exception of an async test case.