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
<PackageReference Include="TXC.MSTest.Matrix" Version="1.0.2" />
<PackageVersion Include="TXC.MSTest.Matrix" Version="1.0.2" />
<PackageReference Include="TXC.MSTest.Matrix" />
paket add TXC.MSTest.Matrix --version 1.0.2
#r "nuget: TXC.MSTest.Matrix, 1.0.2"
#:package TXC.MSTest.Matrix@1.0.2
#addin nuget:?package=TXC.MSTest.Matrix&version=1.0.2
#tool nuget:?package=TXC.MSTest.Matrix&version=1.0.2
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 | Versions 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. |
-
net6.0
- MSTest.TestFramework (>= 3.6.0)
-
net7.0
- MSTest.TestFramework (>= 3.6.0)
-
net8.0
- MSTest.TestFramework (>= 3.6.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.