Skip to content

Conversation

@glennawatson
Copy link
Contributor

This pull request introduces a new LocatorScope helper to safely isolate and restore the global service locator state (Locator.Current) during tests, and applies it to several test fixtures that modify the locator. This change ensures better test reliability and prevents state leakage between tests. Additionally, the documentation is updated to reflect the new approach.

Test isolation improvements:

  • Added a new LocatorScope class in ReactiveUI.Tests.Infrastructure.StaticState to snapshot and restore Locator.Current during tests, preventing global state leakage and making tests more reliable.
  • Updated test fixtures (CommandBindingTests, MessageBusTest, RoutedViewHostTests, ViewModelViewHostTests) to use LocatorScope in their setup and teardown methods, ensuring the service locator is properly isolated for each test run. [1] [2] [3] [4]

Test metadata and documentation:

  • Marked WhenAnyObservableTests as [NotInParallel] and added XML documentation explaining the need for test isolation due to reliance on the service locator.
  • Updated using statements to import the new LocatorScope where required. [1] [2]

Documentation updates:

  • Removed the outdated StaticState/README.md and replaced its guidance with the new LocatorScope approach for managing static state in tests.

@codecov
Copy link

codecov bot commented Dec 29, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.75%. Comparing base (69b64a1) to head (2396afe).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4251   +/-   ##
=======================================
  Coverage   88.75%   88.75%           
=======================================
  Files         169      169           
  Lines        7522     7522           
  Branches     1241     1241           
=======================================
  Hits         6676     6676           
  Misses        672      672           
  Partials      174      174           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@glennawatson glennawatson merged commit 22d5bb5 into main Dec 29, 2025
6 checks passed
@glennawatson glennawatson deleted the glennawatson/fix-locator-tests branch December 29, 2025 23:15
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants