GitXplorerGitXplorer
A

Xunit.StaFact

public
93 stars
32 forks
8 issues

Commits

List of commits on branch main.
Verified
c56ccf385d4f9f4bf818360c8a884746588a363b

Merge pull request #115 from AArnott/auto/libtemplateUpdate

AAArnott committed 5 days ago
Unverified
b4303fd64cf63ed8c32240537fdf4cf60d7b32a8

Merge branch 'main' of https://github.com/aarnott/Library.Template into auto/libtemplateUpdate

AAArnott committed 5 days ago
Verified
b47196d0fd54776d22fea52f03d75086cc071ffe

Update nbgv and nerdbank.gitversioning updates to 3.7.115 (#338)

rrenovate[bot] committed 7 days ago
Verified
aa04b307254cf11d1ac3f28a03fe02dd063f94ef

Merge latest Library.Template (#113)

AAArnott committed 8 days ago
Verified
70fb10f22007f8dcf043c259fc1968a83b899475

Merge the main branch from https://github.com/aarnott/Library.Template

AAArnott committed 8 days ago
Verified
048010c3a101eb0b26965759e55b188dd576c37f

Update xunit (#336)

rrenovate[bot] committed 8 days ago

README

The README file for this repository.

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 Yes1 yes2
[WpfFact, WpfTheory] Windows only3 DispatcherSynchronizationContext yes
[WinFormsFact, WinFormsTheory] Windows only3 WindowsFormsSynchronizationContext yes
[StaFact, StaTheory] Windows only3 No yes
[CocoaFact, CocoaTheory] Mac OSX only3 Yes1 no

1 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.

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

3 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.