Getting Started
Installation
Consume this library via its NuGet Package. Click on the badge to find its latest version and the instructions for consuming it that best apply to your project.
Usage
Always use the SkippableFactAttribute or SkippableTheoryAttribute on test methods that you want to potentially skip for.
Conditional runtime skipping
Use methods on the Skip class to skip a test based on some runtime check.
This can be useful when you need to test for specific runtime conditions. It can also be useful to skip certain test cases in a theory when input combinations are invalid.
[SkippableFact]
public void RuntimeCheck()
{
Skip.IfNot(Environment.GetEnvironmentVariable("RunThisTest") == "true");
}
Exceptions thrown
You can also automatically report tests as skipped based on specific exception types. This is particularly useful when the test runs against multiple target frameworks and your library is not expected to be implemented in some of them. For example:
[SkippableFact(typeof(NotSupportedException), typeof(NotImplementedException))]
public void TestFunctionalityWhichIsNotSupportedOnSomePlatforms()
{
// Test functionality. If it throws any of the exceptions listed in the attribute,
// a skip result is reported instead of a failure.
}
Supported platforms
Apply the SupportedOSPlatformAttribute and/or UnsupportedOSPlatformAttribute to a test method or test class to skip it based on the platform the test is running on.
public class AnyTestClass
{
[SkippableFact]
[SupportedOSPlatform("Windows")]
public void TestCngKey()
{
var key = CngKey.Create(CngAlgorithm.Rsa);
Assert.NotNull(key);
}
}
[SupportedOSPlatform("Windows")]
public class WindowsOnlyTestClass
{
[SkippableFact]
public void SomeTest()
{
// This test will only run on Windows.
}
}
Without [SupportedOSPlatform("Windows")] the CA1416 code analysis warning would trigger:
This call site is reachable on all platforms. 'CngKey. Create(CngAlgorithm)' is only supported on: 'windows'.
Adding [SupportedOSPlatform("Windows")] both suppresses this platform compatibility warning and skips the test when running on Linux or macOS.