Skip to content

Run xunit tests on STA thread with various SynchronizationContexts to emulate windowing applications for more reliable unit testing.

License

Notifications You must be signed in to change notification settings

Weingartner/Xunit.StaFact

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Xunit.StaFact

Build status NuGet package

This project allows for Xunit tests to run on an STA thread instead of the default MTA. It also offers attributes that apply the WPF or Windows Forms SynchronizationContexts to that thread to more fully emulate a windowed application and to ensure that async tests resume execution on the same thread as they would in a real app.

A pure portable UIFactAttribute is also offered for basic UI thread behavior that doesn't tie directly to a specific GUI framework.

Installation

This project is available as a NuGet package

Samples

[WpfFact]
public async Task WpfFact_OnSTAThread()
{
    Assert.Equal(ApartmentState.STA, Thread.CurrentThread.GetApartmentState());
    await Task.Yield();
    Assert.Equal(ApartmentState.STA, Thread.CurrentThread.GetApartmentState()); // still there
}

See more samples.

About

Run xunit tests on STA thread with various SynchronizationContexts to emulate windowing applications for more reliable unit testing.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%