MSTestEnhancer 1.3.0
See the version list below for details.
dotnet add package MSTestEnhancer --version 1.3.0
NuGet\Install-Package MSTestEnhancer -Version 1.3.0
<PackageReference Include="MSTestEnhancer" Version="1.3.0" />
paket add MSTestEnhancer --version 1.3.0
#r "nuget: MSTestEnhancer, 1.3.0"
// Install MSTestEnhancer as a Cake Addin #addin nuget:?package=MSTestEnhancer&version=1.3.0 // Install MSTestEnhancer as a Cake Tool #tool nuget:?package=MSTestEnhancer&version=1.3.0
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
- Install MSTestEnhancer from the nuget.org.
- Write unit test code in the style listed below.
Recommended Style of Writing Unit Tests
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.
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 | Versions 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. |
-
.NETFramework 4.5
- MSTest.TestFramework (>= 1.2.0)
- System.ValueTuple (>= 4.4.0)
-
.NETFramework 4.7
- MSTest.TestFramework (>= 1.2.0)
-
.NETStandard 2.0
- MSTest.TestFramework (>= 1.2.0)
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 (2)
Showing the top 2 popular GitHub repositories that depend on MSTestEnhancer:
Repository | Stars |
---|---|
lindexi/lindexi_gd
博客用到的代码
|
|
dotnet-campus/AsyncWorkerCollection
高性能的多线程异步工具库。A collection of tools that support asynchronous methods and support high-performance multithreading.
|
Version | Downloads | Last updated |
---|---|---|
2.2.1 | 1,281 | 10/27/2022 |
2.2.1-alpha01 | 2,752 | 2/21/2022 |
2.2.0 | 5,882 | 1/6/2022 |
2.1.2-alpha03 | 205 | 12/27/2021 |
2.1.2-alpha02 | 189 | 12/27/2021 |
2.1.2-alpha01 | 164 | 12/27/2021 |
2.1.1 | 1,302 | 8/4/2021 |
2.1.1-alpha02 | 220 | 8/4/2021 |
2.1.1-alpha01 | 267 | 8/4/2021 |
2.1.0 | 3,774 | 3/4/2021 |
2.0.2-alpha03 | 130 | 8/10/2023 |
2.0.2-alpha02 | 156 | 4/18/2023 |
2.0.1 | 4,788 | 5/24/2020 |
1.6.0 | 3,152 | 6/21/2018 |
1.4.0 | 1,307 | 3/20/2018 |
1.3.0 | 946 | 2/26/2018 |
1.2.1 | 913 | 2/24/2018 |
1.2.0 | 903 | 2/13/2018 |
1.1.0 | 924 | 2/12/2018 |
1.0.0 | 938 | 2/11/2018 |
1. Give suggestions if the user uses same contract strings.
2. Add arguments automatically at the end of contract string if the user doesn't write formatted contract string.