TXC.MSTest.Matrix 1.0.2

dotnet add package TXC.MSTest.Matrix --version 1.0.2
                    
NuGet\Install-Package TXC.MSTest.Matrix -Version 1.0.2
                    
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="TXC.MSTest.Matrix" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TXC.MSTest.Matrix" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="TXC.MSTest.Matrix" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TXC.MSTest.Matrix --version 1.0.2
                    
#r "nuget: TXC.MSTest.Matrix, 1.0.2"
                    
#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.
#:package TXC.MSTest.Matrix@1.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TXC.MSTest.Matrix&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=TXC.MSTest.Matrix&version=1.0.2
                    
Install as a Cake Tool

MSTest Matrix Extension

The MatrixParameterAttribute allows you to run the same test method with a combination of multiple different inputs. It must appear multiple times on a test method, otherwise it will throw an exception, since it is pretty meaningless with only parameter. It should be combined with TestMethodAttribute and MatrixAttribute.

It generates multiple test cases beforehand, instead of having multiple test results under a single test.

It also contains exclusions support.

Explanation

Each attribute MatrixParameter() results in a parameter for the method.

So with three attributes, the testmethod should accept 3 parameters.

How to use

The following test generates a total of 16 combinations: 1 + 2, 1 + 4, 1 + 6, 1 + 8, 3 + 2 and so on...

public class MyUnitTest
{
    ...
    [TestMethod]
    [Matrix]
    [MatrixParameter(1, 3, 5, 7)]
    [MatrixParameter(2, 4, 6, 8)]
    public void TestMatrixWithTwoParameters(int a, int b)
    {
        int result = a + b;
        Assert.IsTrue(result > 0);
        Assert.IsFalse(result % 2 == 0);
    }
    ...
}

The following test generates a total of 15 combinations: 0 + 1 + 3, 0 + 1 + 4, 0 + 1 + 5, ... 0 + 2 + 7, ... 9 + 2 + 3 and so on...

public class MyUnitTest
{
    ...
    [TestMethod]
    [Matrix]
    [MatrixParameter(0, 9)]
    [MatrixParameter(1, 2)]
    [MatrixParameter(3, 4, 5, 7)]
    [MatrixExclude(9, 1, 4)]
    public void TestMatrix(int a, int b, int c)
    {
        int result = a + b + c;
        Assert.IsTrue(result > 0);
    }
    ...
}
public class MyUnitTest
{
    ...
    [TestMethod]
    [Matrix(DisplayName = "My Custom DisplayName")]
    [MatrixParameter("value1.1", "value1.2", "value1.3")]
    [MatrixParameter("value2.1", "value2.2", "value2.3")]
    public void TestDisplayName(string a, string b)
    {
      ...
    }
    ...
}

How to exclude a combination

The following test will exclude the following combination: 0 + 0, 3 + 4 and 7 + 8.

public class MyUnitTest
{
    ...
    [TestMethod]
    [Matrix]
    [MatrixParameter(0, 1, 3, 5, 7)]
    [MatrixParameter(0, 2, 4, 6, 8)]
    [MatrixExclude(0, 0), MatrixExclude(0, 2), MatrixExclude(0, 4)]
    [MatrixExclude(0, 4), MatrixExclude(0, 6), MatrixExclude(0, 8)]
    public void TestMatrixWithTwoParametersAndExcludes(int a, int b)
    {
        int result = a + b;
        Assert.IsTrue(result > 0);
        Assert.IsFalse(result % 2 == 0);
    }
    ...
}
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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 is compatible.  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 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.2 119 11/17/2024
1.0.1 110 11/17/2024
1.0.0 106 11/16/2024