MSTestEnhancer 1.6.0

MSTestEnhancer helps you to write unit tests without naming any method. You can write method contract descriptions instead of writing confusing test method name when writing unit tests.

Install-Package MSTestEnhancer -Version 1.6.0
dotnet add package MSTestEnhancer --version 1.6.0
paket add MSTestEnhancer --version 1.6.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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.

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.

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.

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.

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.

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.

Release Notes

Add some assersion extensions.

Version History

Version Downloads Last updated
1.6.0 187 6/21/2018
1.4.0 165 3/20/2018
1.3.0 119 2/26/2018
1.2.1 93 2/24/2018
1.2.0 119 2/13/2018
1.1.0 101 2/12/2018
1.0.0 105 2/11/2018