Coder Social home page Coder Social logo

xunit-extensions's Introduction

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));
}

xunit-extensions's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar natemcmaster avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

xunit-extensions's Issues

A bout xunit framework

Sorry to bother you, I am studying how to develop a unit-test-framework, and I see your project xunit-extensions, that's a good sample for me to understand how to work and what is my first step, but a very confuse question for me. That's why I can click run test button and my unit-test-framework will working, I don't know from the project can you tell me why and help me what document record this

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.