natemcmaster - McMaster.Extensions.Xunit 0.1.0-rtm.19
Extensions and utilities for XUnit.NET test projects
This includes API for making tests dynamically skippable, asserting timeouts on async tasks, and other helpful utilities.
Commonly used types: McMaster.Extensions.Xunit.SkippableFact McMaster.Extensions.Xunit.SkippableTheory
PM> Install-Package McMaster.Extensions.Xunit -Version 0.1.0-rtm.19 -Source https://www.myget.org/F/natemcmaster/api/v3/index.json
> nuget.exe install McMaster.Extensions.Xunit -Version 0.1.0-rtm.19 -Source https://www.myget.org/F/natemcmaster/api/v3/index.json
> dotnet add package McMaster.Extensions.Xunit --version 0.1.0-rtm.19 --source https://www.myget.org/F/natemcmaster/api/v3/index.json
source https://www.myget.org/F/natemcmaster/api/v3/index.json
nuget McMaster.Extensions.Xunit ~> 0.1.0-rtm.19
Copy to clipboard
> choco install McMaster.Extensions.Xunit --version 0.1.0-rtm.19 --source https://www.myget.org/F/natemcmaster/api/v2
Import-Module PowerShellGet
Register-PSRepository -Name "natemcmaster" -SourceLocation "https://www.myget.org/F/natemcmaster/api/v2"
Install-Module -Name "McMaster.Extensions.Xunit" -RequiredVersion "0.1.0-rtm.19" -Repository "natemcmaster" -AllowPreRelease
Copy to clipboard
Xunit Extensions
This repo contains a class library of utilities and helpers for writing tests with XUnit.NET.
Getting started
Install this as a NuGet package using your favorite IDE.
Install-Package McMaster.Extensions.Xunit
dotnet add package McMaster.Extensions.Xunit
Dynamically skip tests
In many cases, it's useful to automatically skip tests, based on conditions that cannot be determined at compile-time.
Test conditions you can use include
- SkipOnOS (skip on certain operating systems)
- SkipInEnvironment (skip if certain environment variables are set)
- SkipOnRuntimes (only run tests on Mono, .NET Core, or .NET Framework)
- SkipIfNotDocker (only run tests if running inside a Docker container)
- Your own (if you write a test that implements
ITestCondition)
using McMaster.Extensions.Xunit;
public class MyTests
{
[SkippableFact]
[SkipOnOS(OS.Linux | OS.MacOS)
public void RunCommandPrompt()
{
Process.Start("cmd.exe", "/c dir").WaitForExit();
}
[SkippableFact]
[SkipUnlessIsNoon]
public void Test1() { }
// Implement your own conditional logic by implementing ITestCondition
public class SkipUnlessIsNoonAttribute : Attribute, ITestCondition
{
public bool IsMet => DateTime.Now.Hours == 12;
public string SkipReason { get; } = "This test can only run at noon."
}
}
Test in different cultures
Ensure tests run with a particular culture set.
using McMaster.Extensions.Xunit;
public class I18nTests
{
[Fact]
[UseCulture("fr-FR")
public void TestInFrench()
{
}
}
Misc
Other useful helpers are included.
Task.TimeoutAfter - prevent async from running too long
[Fact]
public async Task Test()
{
await thing.TimeoutAfter(TimeSpan.FromMinutes(4));
}
-
.NETFramework 4.5.2
- System.Runtime.InteropServices.RuntimeInformation (>= 4.3.0)
- xunit.extensibility.core (>= 2.3.1)
- xunit.extensibility.execution (>= 2.3.1)
-
.NETStandard 2.0
- xunit.extensibility.core (>= 2.3.1)
- xunit.extensibility.execution (>= 2.3.1)
- .NETFramework 4.5.2: 4.5.2.0
- .NETStandard 2.0: 2.0.0.0
OwnersNate McMaster |
AuthorsNate McMaster |
Project URLhttps://github.com/natemcmaster/xunit-extensions |
LicenseApache-2.0 |
Tagsxunit testing |
Info564 total downloads |
| 74 downloads for version 0.1.0-rtm.19 |
| Download (45.69 KB) |
| Found on the current feed only |
Package history
| Version | Size | Last updated | Downloads | Mirrored? | |||
|---|---|---|---|---|---|---|---|
|
|
0.1.0 | 45.33 KB | Tue, 12 Jun 2018 07:00:56 GMT | 71 |
|
||
|
|
0.1.0-rtm.26 | 45.7 KB | Sun, 23 Feb 2020 18:07:11 GMT | 62 |
|
||
|
|
0.1.0-rtm.24 | 45.71 KB | Tue, 24 Sep 2019 03:46:49 GMT | 70 |
|
||
|
|
0.1.0-rtm.21 | 45.72 KB | Sat, 21 Sep 2019 05:20:22 GMT | 72 |
|
||
|
|
0.1.0-rtm.19 | 45.69 KB | Sat, 21 Sep 2019 05:16:47 GMT | 74 |
|
||
|
|
0.1.0-rtm.16 | 45.7 KB | Sat, 21 Sep 2019 05:13:21 GMT | 65 |
|
||
|
|
0.1.0-rtm.10 | 45.38 KB | Tue, 19 Feb 2019 23:12:30 GMT | 76 |
|
||
|
|
0.1.0-rtm.8 | 45.33 KB | Tue, 12 Jun 2018 06:56:41 GMT | 74 |
|