-
Notifications
You must be signed in to change notification settings - Fork 291
Open
Labels
Area: FixturesArea: MSTestIssues with MSTest that are not specific to more refined area (e.g. analyzers or assertions)Issues with MSTest that are not specific to more refined area (e.g. analyzers or assertions)
Milestone
Description
Describe the bug
It's common to use a custom SynchronizationContext (e.g. UnitTestSynchronizationContext) for unit testing of client applications (e.g. MAUI, WPF, WinForms). This allows to simulate the same async behavior in the unit test environment as we have in the application.
We initialize the custom SynchronizationContext in a TestInitialize method and dispose it in TestCleanup. This worked fine for more than 10 years (even with legacy MSTest v1).
Starting with MSTest v4 this approach does not work anymore. The SynchronizationContext.Current is now null in the test method.
- Last working version: 3.9.3
- Not working version: 4.02
Steps To Reproduce
- Clone repo MSTestSynchronizationContextIssue
- It contains 3 projects:
- ❌
UnitTest.MSTest: Uses MSTest 4.0.2. This one fails because the SynchonizationContext is set to null before calling the test method. - ✅
UnitTestOld.MSTest: Uses MSTest 3.9.3. This one passes as it works as expected. - ✅
UnitTest.XUnit: Uses the latest Xunit v3 with the same approach. This one passes as it works as expected.
- ❌
Metadata
Metadata
Assignees
Labels
Area: FixturesArea: MSTestIssues with MSTest that are not specific to more refined area (e.g. analyzers or assertions)Issues with MSTest that are not specific to more refined area (e.g. analyzers or assertions)