SparkyTestHelpers.Scenarios.MsTest
1.1.0
See the version list below for details.
dotnet add package SparkyTestHelpers.Scenarios.MsTest --version 1.1.0
NuGet\Install-Package SparkyTestHelpers.Scenarios.MsTest -Version 1.1.0
<PackageReference Include="SparkyTestHelpers.Scenarios.MsTest" Version="1.1.0" />
<PackageVersion Include="SparkyTestHelpers.Scenarios.MsTest" Version="1.1.0" />
<PackageReference Include="SparkyTestHelpers.Scenarios.MsTest" />
paket add SparkyTestHelpers.Scenarios.MsTest --version 1.1.0
#r "nuget: SparkyTestHelpers.Scenarios.MsTest, 1.1.0"
#addin nuget:?package=SparkyTestHelpers.Scenarios.MsTest&version=1.1.0
#tool nuget:?package=SparkyTestHelpers.Scenarios.MsTest&version=1.1.0
This package contains an implementation of SparkyTestHelpers.Scenarios for "MsTest" / VisualStudio.TestTools.
The only differences are:
- If you use MsTest's
Assert.Inconclusive()
in a scenario test, your scenario "suite" will be recognized as inconclusive and not as a failure by the Visual Studio test runner. - The "using" statement is
using SparkyTestHelpers.Scenarios.MsTest;
instead ofusing SparkyTestHelpers.Scenarios;
MsTestScenarioTester<TScenario>
class SparkyTestHelpers.Scenarios.MsTest.MsTestScenarioTester<TScenario>
VisualStudio.TestTools doesn't have "RowTest" or "TestCase" attributes like NUnit or other .NET testing frameworks. (It does have a way to do data-driven tests, but it's pretty cumbersome.) This class provides the ability to execute the same test code for multiple test cases and, after all test cases have been executed, failing the unit test if any of the test cases failed.
This class is rarely used directly. It is more often used via the IEnumerable<TScenario>.TestEach extension method (see below).
When one or more of the test scenarios fails, the failure exception shows which were unsuccessful, for example, this scenario test:
ForTest.Scenarios
(
new { DateString = "1/31/2023", ShouldBeValid = true },
new { DateString = "2/31/2023", ShouldBeValid = true },
new { DateString = "3/31/2023", ShouldBeValid = true },
new { DateString = "4/31/2023", ShouldBeValid = true },
new { DateString = "5/31/2023", ShouldBeValid = true },
new { DateString = "6/31/2023", ShouldBeValid = false }
)
.TestEach(scenario =>
{
DateTime dt;
Assert.AreEqual(scenario.ShouldBeValid, DateTime.TryParse(scenario.DateString, out dt));
});
...throws this exception:
Test method SparkyTestHelpers.UnitTests.DateTests threw exception:
SparkyTestHelpers.Scenarios.ScenarioTestFailureException: Scenario[1] (2 of 6) - Assert.AreEqual failed. Expected:<True>. Actual:<False>.
Scenario data - anonymousType: {"DateString":"2/31/2023","ShouldBeValid":true}
Scenario[3] (4 of 6) - Assert.AreEqual failed. Expected:<True>. Actual:<False>.
Scenario data - anonymousType: {"DateString":"4/31/2023","ShouldBeValid":true}
MsTestScenarioTesterExtension
class SparkyTestHelpers.Scenarios.MsTest.MsTestScenarioTesterExtension
MsTestScenarioTester<TScenario> extension methods.
Static Methods
- MsTestScenarioTester<TScenario> TestEach (IEnumerable<TScenario> enumerable, Action<TScenario> test)
Example
using SparkyTestHelpers.Scenarios.MsTest;
new []
{
new { DateString = "1/31/2023", ShouldBeValid = true },
new { DateString = "2/31/2023", ShouldBeValid = false },
new { DateString = "3/31/2023", ShouldBeValid = true },
new { DateString = "4/31/2023", ShouldBeValid = false },
new { DateString = "5/31/2023", ShouldBeValid = true },
new { DateString = "6/31/2023", ShouldBeValid = false }
}
.TestEach(scenario =>
{
DateTime dt;
Assert.AreEqual(scenario.ShouldBeValid, DateTime.TryParse(scenario.DateString, out dt));
});
ForTest
class SparkyTestHelpers.Scenarios.MsTest.ForTest
"Syntactic sugar" methods for working with MsTestScenarioTester<TScenario>
Static Methods
- TScenario[] Scenarios (TScenario[] scenarios) - creates array of scenarios that can be "dotted" to the TestEach extension method:
Example
using SparkyTestHelpers.Scenarios.MsTest;
ForTest.Scenarios
(
new { DateString = "1/31/2023", ShouldBeValid = true },
new { DateString = "2/31/2023", ShouldBeValid = false },
new { DateString = "3/31/2023", ShouldBeValid = true },
new { DateString = "4/31/2023", ShouldBeValid = false },
new { DateString = "5/31/2023", ShouldBeValid = true },
new { DateString = "6/31/2023", ShouldBeValid = false }
)
.TestEach(scenario =>
{
DateTime dt;
Assert.AreEqual(scenario.ShouldBeValid, DateTime.TryParse(scenario.DateString, out dt));
});
- IEnumerable<TEnum> EnumValues () - tests each value in an enum.
Example
using SparkyTestHelpers.Scenarios.MsTest;
ForTest.EnumValues<OrderStatus>()
.TestEach(orderStatus => foo.Bar(orderStatus));
- IEnumerable<TEnum> ExceptFor (IEnumerable<TEnum> values, TEnum[] valuesToExclude) - Exclude enum values from test scenarios.
Example
using SparkyTestHelpers.Scenarios.MsTest;
ForTest.EnumValues<OrderStatus>()
.ExceptFor(OrderStatus.Cancelled)
.TestEach(orderStatus => foo.Bar(orderStatus));
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. 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. |
.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 | net461 was computed. net462 was computed. net463 was computed. net47 was computed. 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. |
-
.NETStandard 2.0
- MSTest.TestFramework (>= 1.1.18)
- SparkyTestHelpers (>= 1.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
V1.1.0: Added ScenarioTester<TScenario> "BeforeEachTest" and "AfterEachTest" methods.