Repository navigation
Conversation
…unit#1549) Under Microsoft.Testing.Platform the executor subscribed to Console.CancelKeyPress unconditionally. On Android, iOS, tvOS and browser that throws PlatformNotSupportedException from the constructor, so no test ran. Subscribe in a try/catch for that exception, and unsubscribe in Dispose only when the subscription succeeded.
Author
|
@dotnet-policy-service agree |
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the console-subscription change.
No open issues 🎉
What changed in this PR
Addresses #1549 by preventing unsupported Console.CancelKeyPress subscriptions from blocking Microsoft.Testing.Platform executor construction. This removes the first Android startup blocker; the engine limitations tracked in #1551 remain outside this PR.
Changes:
- Catch
PlatformNotSupportedExceptionduring subscription while allowing other exceptions to propagate. - Unsubscribe during disposal only when registration succeeded.
- Add tests for subscription outcomes, exception propagation, and MTP executor creation/disposal.
| File | Description |
|---|---|
| src/NUnitTestAdapterTests/CancelKeyPressTests.cs | Adds subscription behavior tests and an executor lifecycle smoke test. |
| src/NUnitTestAdapter/NUnit3TestExecutor.cs | Guards unsupported console subscriptions and tracks successful registration for cleanup. |
Review effort: Balanced
OsirisTerje
approved these changes
Nov 22, 2026
Member
|
@zhollis21 Can you check this again, as main now have engine 3.23.0, which includes the engine fix. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1549
Under Microsoft.Testing.Platform, the
NUnit3TestExecutorconstructor subscribes toConsole.CancelKeyPressunconditionally. The runtime marks that event unsupported on Android, iOS, tvOS and browser, so on Android the constructor throwsPlatformNotSupportedExceptionbefore any test runs.The change:
try/catch (PlatformNotSupportedException). I chose this overOperatingSystem.IsAndroid()and friends because the adapter also targets net462, whereOperatingSystemdoesn't exist. It also covers any other platform that throws.Disposeonly unsubscribes when the subscription succeeded, so it doesn't throw (and log) the same exception again.CancelKeyPressTests: a subscription that throwsPlatformNotSupportedExceptionis skipped; a normal one subscribes; other exceptions still propagate; an MTP executor can be created and disposed..\build -t testpasses on net462 and net8.0.Checked on an Android emulator
I used a
dotnet new androidtestproject (net11.0-android, x86_64 emulator, API 36), switched from MSTest to NUnit 5.0.0 + NUnit3TestAdapter withEnableNUnitRunnerandbuilder.AddNUnit(...), and randotnet test --device <emulator>:PlatformNotSupportedException(0 tests).RunTests.To be clear about what this does not show: no NUnit test runs on the device yet. After this fix, the run stops in the NUnit engine (the extension directory scan, then engine and test-assembly loading). I've written those up separately in nunit/nunit-console#1966, since they are a bigger question than this bug. This PR removes the first blocker and is safe on every platform on its own.