Skip to content

Let the v3 engine run tests on Android in Debug builds - #1967

Merged
oznetmaster merged 2 commits into
nunit:version3from
zhollis21:fix/v3-engine-on-android
Nov 15, 2026
Merged

oznetmaster merged 2 commits into
nunit:version3from
zhollis21:fix/v3-engine-on-android

Conversation

@zhollis21

@zhollis21 zhollis21 commented Nov 14, 2026 •

Copy link
Copy Markdown

Part of #1966. Scoped to three robustness fixes: they let Debug builds run on Android, but Release still runs no tests (see below), and that stays tracked in #1966.

With these changes and nunit/nunit3-vs-adapter#1550, a Debug dotnet test --device run on an Android emulator gets through discovery and execution: 1 passed, 1 failed, 1 skipped, which is what the repro's tests are written to produce.

Changes

DirectoryFinder: skip folders that cannot be listed. The extension scan walks every parent folder of the engine. On Android the engine is under /data/user/0/<package>/files/..., and listing /data/user/0 throws UnauthorizedAccessException, which ended the whole scan. A folder we may not list now contributes no matches. Two new tests in DirectoryFinderTests cover the single-level and ** cases; both fail without the change.

ExtensionManager.FindExtensionAssemblies: return early when the host assembly has no location. In Release the engine is packed inside the APK, so Assembly.Location is empty, and Path.Combine(Path.GetDirectoryName(""), ...) threw ArgumentNullException. An assembly that is not a file has no folders around it to search. The new test loads an assembly from bytes, which has an empty Location on desktop too, and fails without the change with the same exception seen on the device.

TestAssemblyResolver: go without AssemblyDependencyResolver where it is not supported. Its constructor throws PlatformNotSupportedException on mobile runtimes, which surfaced as "Failed to load the test assembly" from NUnitNetCore31Driver.Load. There is no deps.json to read there, so the resolver now catches that one exception and relies on its other strategies. This one only happens on a mobile runtime, so it's verified on the emulator only.

Not covered: Release

With the ExtensionManager change, a Release run no longer errors, but it reports zero tests. The test assembly is also inside the APK, with an empty Location, and the adapter and engine identify test assemblies by file path, so there is no path to hand the engine. #1808's already-loaded lookup matches by path too. I don't think that has a narrow fix: it needs a way to pass an already-loaded Assembly through, which is the design question in #1966.

Testing

Two desktop assumptions stopped a Debug `dotnet test --device` run on an
Android emulator before any test ran (nunit#1966):

- The extension scan walks every parent folder of the engine, and Android
  denies listing some of them, such as /data/user/0. DirectoryFinder now
  treats a folder it may not list as having no matches.
- TestAssemblyResolver constructs an AssemblyDependencyResolver, which
  throws PlatformNotSupportedException on mobile runtimes. There is no
  deps.json to read there, so the resolver now goes without it and relies
  on its other strategies.
In an Android Release build the engine is packed inside the APK, so its
Assembly.Location is empty. FindExtensionAssemblies passed
Path.GetDirectoryName("") (null) to Path.Combine, which threw
ArgumentNullException before any test could run (nunit#1966). An assembly that
is not a file has no folders around it to search, so the scan now returns
early.
@zhollis21 zhollis21 changed the title Let the v3 engine run tests on Android (Debug) Let the v3 engine run tests on Android Nov 14, 2026

@oznetmaster oznetmaster left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhollis21, I reviewed head e943786 and ran the additional Windows desktop checks requested by @CharliePoole.

  • Complete engine-core suite on .NET 8: 452 passed, zero failed, one skipped.
  • Complete engine-core suite on .NET Framework: 622 passed, zero failed, fourteen inconclusive, one skipped.
  • All three new desktop regressions fail with the original DirectoryFinder/ExtensionManager code and pass after restoring the PR, on both targets.
  • Our existing NUnit 5 entry-point probes pass on Framework, .NET 8 and .NET 10: discovery, exact filtering, passing/failing results and cooperative cancellation, including token delivery and finally/teardown receipts.

Building the complete solution supplies the FakeExtensions test data, so the twelve missing-fixture failures in the description do not reproduce here. The full build succeeds with the SDK's existing net6.0 end-of-support warning; no source change or warning suppression was needed.

I found no blocking issue in the narrow desktop changes. I also checked that the current filesystem wrapper materializes its directory results within GetDirectories, so its access-denied exception is inside the new catch. The resolver fallback catches PlatformNotSupportedException specifically, preserving other initialization failures.

These results do not independently validate Android or resolve Release APK discovery. The reporter's device evidence remains the validation for the unsupported-resolver path, and the zero-test Release case should remain tracked separately. The PR can be assessed as these scoped corrections without claiming full Android support.

No merge while Charlie's hold remains in effect.

Neil Colvin, with assistance from OpenAI Codex.

@CharliePoole

Copy link
Copy Markdown
Member

@oznetmaster My request to hold back updates applies to main, not version3. However, we still need to decide whether this is worth doing without the Release portion. @zhollis21 placed this in draft status as well.

A key question is whether we can pass a loaded assembly as a byte array and load it that way. I haven't had time to examine the V3 code but I believe we once had that ability. Since we never really used it as intended, it may have been removed.

We won't be releasing 3.23.0 until the .NET 11.0 agent is merged to it, so this could be a problem for next week. :-)

Copy link
Copy Markdown
Collaborator

@CharliePoole, thanks for clarifying that the hold applies to main rather than version3. I will keep that distinction explicit; #1967 remains a draft pending the scope decision.

I checked the current v3 path and ran a small desktop probe against this PR's unchanged engine binaries. A fixture loaded with Assembly.Load(byte[]) has an empty Location. The existing file-based lookup does not select it, the driver rejects an empty path, and DriverService rejects a missing file before selecting a framework driver. IFrameworkDriver.Load still accepts a string path; I have not found a current public engine entry point accepting an Assembly or its bytes.

The lower-level framework capability does exist: passing that same byte-loaded Assembly directly to FrameworkController discovers all ten fixture cases. That probe used NUnit 5.1.0-alpha.0.50 on Windows/.NET 10; it is not Android validation. It demonstrates the distinction between framework support and the adapter/engine plumbing needed to reach it. I have not established when any earlier engine byte-array support was removed.

My preference is to agree the limited scope with @zhollis21: the three robustness fixes can be useful independently, but the PR should not imply complete Android support. If Debug-only support is acceptable for 3.23.0, I would keep the Release/loaded-assembly work tracked in #1966 and describe this PR accordingly. If the acceptance requirement is working Release packaging, it should remain a draft until that path is proven. I would avoid making a broader adapter redesign an implicit part of these three fixes.

Neil Colvin, with assistance from OpenAI Codex.

@CharliePoole

Copy link
Copy Markdown
Member

@zhollis21 If you want to have the PR merged into the version3 branch for inclusion in the next release, please remove the draft status and let @oznetmaster know.

@zhollis21 zhollis21 changed the title Let the v3 engine run tests on Android Let the v3 engine run tests on Android in Debug builds Nov 15, 2026
@zhollis21
zhollis21 marked this pull request as ready for review November 15, 2026 01:31
@zhollis21

Copy link
Copy Markdown
Author

@oznetmaster Thanks for the review and the extra probes. I've taken this out of draft and retitled it for Debug builds, so it doesn't claim full Android support. Release and the loaded-assembly path stay tracked in #1966. It's ready for you whenever suits.

@oznetmaster oznetmaster left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhollis21, thank you for narrowing the title and description to the three robustness fixes and Debug support, with Release APK discovery remaining in #1966.

The source is still e943786, which I reviewed and validated above. The complete desktop core suites, additional NUnit 5 entry-point probes and three before/after regressions remain applicable; hosted CI and CLA are green.

Approved for this scoped change to version3. This does not establish Android Release support or a file-free adapter/engine loading path. Charlie has clarified that his synchronization hold applies to main, not version3.

Neil Colvin, with assistance from OpenAI Codex.

@oznetmaster
oznetmaster merged commit 84a99af into nunit:version3 Nov 15, 2026
2 checks passed
@CharliePoole CharliePoole added this to the 3.23.0 milestone Nov 16, 2026
@CharliePoole

CharliePoole commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

@oznetmaster Note labeling change and assignment to @zhollis21. In those rare cases where a PR does not close an issue but accomplishes some improvement that should be included in the generated release notes, this is how I do it.

@CharliePoole

Copy link
Copy Markdown
Member

This issue has been resolved in version 3.23.0

The release is available on:
GitHub.
NuGet packages are also available NuGet.org and
Chocolatey Packages may be found at Chocolatey.org

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants