Xunit 1.9.x provides the user with the DynamicSkipExample.cs example to help him setting up dynamic skipping of a [Fact]
.
This has proven to be quite useful when performing some cross-platform development. This allows a test to be temporarily ignored when it cannot be properly run because of the underlying context (OS, filesystem, ...).
However, this example has been dropped in commit 2deeff5 on the road to version 2.0.
How can one re-implement such a functionality through one of the extensibility points of Xunit 2.0?
Note: An issue about this topic has been raised in the xUnit tracker. See xunit/xunit#250.
[Update: XUnit v2.0 (RTM) is now available and skippable tests are supported by it directly. Use
[Fact (Skip = "specific reason")]
]Note that XUnit v2.0 has not shipped. This example is compatible with Xunit 2.0 beta5 which you can find on nuget.org. There may be other ways to accomplish this (as this is just the example I came to).
1) Define an attribute that will decorate your tests.
2) Create your discoverer. (We followed the code example at https://github.com/xunit/xunit/blob/2d9ce6fbd75e91a69a0cc83e1bc3d4eab18b2c6c/src/xunit.execution/Sdk/Frameworks/TheoryDiscoverer.cs)
3) Create a class which implements IXunitTestCase (as the default base class doesn't allow modifying the skip reason).
You have many options for how you want to set the base.SkipReason. In this sample, a public method was created.
This example will skip tests that have a
MemberDataAttribute
that returns no data rows. You can modify it to return theSkippableTestCase
based on your criteria. For example, this discover skips tests on Sunday.You can also search for SkippableFact in the Nugget Manager, then you can use all functions with [SkippableFact]
This has eventually been fixed in issue xunit/samples.xunit#8.
The amazing @BradWilson made this available as a complete and detailed sample in the samples.xunit repository.