Giter VIP home page Giter VIP logo

fredatgithub / xunit.stafact Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aarnott/xunit.stafact

0.0 1.0 0.0 895 KB

Run your xunit-based tests on an STA thread with the WPF Dispatcher, a WinForms SynchronizationContext, or even a cross-platform generic UI thread emulation with a SynchronizationContext that keeps code running on a "main thread" for that test.

License: Other

C# 68.30% PowerShell 30.87% Batchfile 0.35% Dockerfile 0.48%

xunit.stafact's Introduction

Xunit.StaFact

Build Status NuGet package

Run your xunit-based tests on an STA thread with the WPF Dispatcher, a WinForms SynchronizationContext, or even a cross-platform generic UI thread emulation with a SynchronizationContext that keeps code running on a "main thread" for that test.

Simply use [WpfFact], [WinFormsFact], [StaFact] or the cross-platform [UIFact] on your test method to run your test under conditions that most closely match the main thread in your application.

Theory variants of these attributes allow for parameterized testing. Check out the xunit.combinatorial nuget package for pairwise or combinatorial testing with theories.

Features

The following test attributes are supported:

Xunit test attributes Supported OS's SynchronizationContext STA thread?
[UIFact, UITheory] All Yes¹ yes²
[WpfFact, WpfTheory] Windows only³ DispatcherSynchronizationContext yes
[WinFormsFact, WinFormsTheory] Windows only³ WindowsFormsSynchronizationContext yes
[StaFact, StaTheory] Windows only³ No yes
[CocoaFact, CocoaTheory] Mac OSX only³ Yes¹ no

¹ This is a private SynchronizationContext that works cross-platform and effectively keeps code running on the test's starting thread the way a GUI application's main thread would do.

² STA thread only applies on Windows. On other operating systems, an MTA thread is used.

³ Windows-only attributes result in the test to result in "Skipped" on other operating systems.

We also offer a [UISettingsAttribute] that can be applied to individual test methods or test classes to control the behavior of the various UI test attributes. This attribute offers a means to add automated retries to a test's execution for unstable tests.

Samples

[UIFact] // or [WinFormsFact] or [WpfFact]
public async Task WpfFact_OnSTAThread()
{
    Assert.Equal(ApartmentState.STA, Thread.CurrentThread.GetApartmentState());
    int originalThread = Environment.CurrentManagedThreadId;
    await Task.Yield();
    Assert.Equal(originalThread, Environment.CurrentManagedThreadId); // still there
}

See more samples.

xunit.stafact's People

Contributors

aarnott avatar dependabot[bot] avatar lg2de avatar sharwell avatar stevebush avatar eilon avatar russkie avatar jonathanmendez avatar juchom avatar kartheekp-ms avatar sandyarmstrong avatar serg046 avatar siyugithub avatar xuachen avatar apobekiaris avatar josetr avatar

Watchers

 avatar

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.