natemcmaster - McMaster.Extensions.Xunit 0.1.0-rtm.24

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.24 -Source https://www.myget.org/F/natemcmaster/api/v3/index.json

Copy to clipboard

> nuget.exe install McMaster.Extensions.Xunit -Version 0.1.0-rtm.24 -Source https://www.myget.org/F/natemcmaster/api/v3/index.json

Copy to clipboard

> dotnet add package McMaster.Extensions.Xunit --version 0.1.0-rtm.24 --source https://www.myget.org/F/natemcmaster/api/v3/index.json

Copy to clipboard
<PackageReference Include="McMaster.Extensions.Xunit" Version="0.1.0-rtm.24" />
Copy to clipboard
source https://www.myget.org/F/natemcmaster/api/v3/index.json

nuget McMaster.Extensions.Xunit  ~> 0.1.0-rtm.24
Copy to clipboard

> choco install McMaster.Extensions.Xunit --version 0.1.0-rtm.24 --source https://www.myget.org/F/natemcmaster/api/v2

Copy to clipboard
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.24" -Repository "natemcmaster" -AllowPreRelease
Copy to clipboard

Xunit Extensions

Travis build status AppVeyor build status

NuGet MyGet

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

Owners

Nate McMaster

Authors

Nate McMaster

Project URL

https://github.com/natemcmaster/xunit-extensions

License

Apache-2.0

Tags

xunit testing

Info

564 total downloads
70 downloads for version 0.1.0-rtm.24
Download (45.71 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