Make your Xunit test methods self-determine to report a "skipped" result. Useful for such cases as "not supported on this platform" results or other environmental inputs.


Keywords
skipping, testing, xunit
License
MS-PL
Install
Install-Package Xunit.SkippableFact -Version 1.2.1

Documentation

Xunit.SkippableFact

GitHub Actions status NuGet package

This project allows for Xunit tests that can determine during execution that they should report a "skipped" result. This can be useful when a precondition is not satisfied, or the test is over functionality that does not exist on the platform being tested.

Installation

This project is available as a NuGet package

Usage

Learn more at our documentation site.

Below is a sampling of uses.

Skip based on a runtime check:

[SkippableFact]
public void SomeMoodyTest()
{
    Skip.IfNot(InTheMood);
}

Skip based on a thrown exception:

[SkippableFact(typeof(NotSupportedException))]
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.
}

Skip based on SupportedOSPlatformAttribute:

[SkippableFact, SupportedOSPlatform("Windows")]
public void TestCngKey()
{
    var key = CngKey.Create(CngAlgorithm.Rsa);
    Assert.NotNull(key);
}