Running NUnit tests on an Android device with `dotnet test --device` fails inside the NUnit engine
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 12/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- android, csharp
- Ambito
- mobile-dev, testing
Direzione di ricerca
Start with the stack traces: DirectoryFinder.ExpandOneStep and ExtensionManager.FindExtensionAssemblies for the scan, and TestEngineActivator.CreateInstance with NUnitEngineAdapter.Initialize for the load. The open question is a design choice (make the engine device-aware or bypass it on mobile), so agree on a direction with the maintainers before writing code. Done means the androidtest repro runs NUnit tests on the emulator in Debug and Release.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Follow-up to nunit/nunit3-vs-adapter#1549, found while testing the fix for it (PR nunit/nunit3-vs-adapter#1550).
.NET 10/11 can run MTP test projects on a device with dotnet test --device. The dotnet new androidtest template does this with MSTest. With NUnit instead, the run never gets to a test. Once nunit/nunit3-vs-adapter#1549 is fixed, the failures below are inside the NUnit engine, which assumes the test assembly and the engine are files in a folder it can browse. On Android neither holds.
I'm opening this to ask what direction you'd like, rather than proposing a fix: each workaround I tried only uncovered the next failure.
Versions: NUnit 5.0.0, NUnit3TestAdapter 6.3.1 / main at 7a4456a plus the nunit/nunit3-vs-adapter#1549 fix, nunit.engine 3.22.0, Microsoft.Testing.Platform 2.5.2, .NET SDK 11.0.100, net11.0-android, x86_64 emulator (API 36), run from the command line (no IDE).
Repro:
dotnet new androidtest -n DroidNUnit- Replace the
MSTestpackage withNUnit5.0.0,NUnit3TestAdapterandMicrosoft.Testing.Extensions.TrxReport(the same version as the adapter's MTP). - Change
<EnableMSTestRunner>to<EnableNUnitRunner>andbuilder.AddMSTest(...)tobuilder.AddNUnit(...)inTestInstrumentation.cs, convert the three tests to[Test], and remove the[assembly: Parallelize]. dotnet test --device <emulator>
What fails, in order
1. Console.CancelKeyPress (#1549). Fixed in PR nunit/nunit3-vs-adapter#1550.
2. Debug build: the engine's extension scan reads a folder Android doesn't allow. ExtensionManager.FindExtensionAssemblies(Assembly) walks every parent folder of the engine up to the root, looking for NUnit.Extension.*/**/tools/. The app's assemblies are under /data/user/0/<package>/files/.__override__/x86_64/, and listing /data/user/0 is denied:
System.UnauthorizedAccessException: Access to the path '/data/user/0' is denied.
at NUnit.Engine.Internal.DirectoryFinder.ExpandOneStep(IList`1 dirList, String pattern)
at NUnit.Engine.Internal.DirectoryFinder.GetDirectories(IDirectory startDirectory, String pattern)
at NUnit.Engine.Services.ExtensionManager.FindExtensionAssemblies(Assembly hostAssembly)
at NUnit.Engine.Services.ExtensionService.StartService()
at NUnit.Engine.TestEngine.Initialize()
at NUnit.VisualStudio.TestAdapter.NUnitEngine.NUnitEngineAdapter.GetService[T]()
at NUnit.VisualStudio.TestAdapter.NUnit3TestExecutor.CreateTestFilterBuilder(IDumpXml dump)
TestEngine.Initialize always adds ExtensionService, so I found no way to skip it. As far as I can see, neither the version3 branch nor main of nunit-console catches this.
3. Release build: the engine can't be loaded from a path. In Release the assemblies are packed inside the APK, so Assembly.Location is empty. TestEngineActivator.CreateInstance() builds /nunit.engine.dll from it and throws. NUnitEngineAdapter.Initialize only falls back to new TestEngine() when the activator returns null:
System.IO.FileNotFoundException: Could not load file or assembly '/nunit.engine.dll'.
at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String)
at NUnit.Engine.TestEngineActivator.CreateInstance()
at NUnit.VisualStudio.TestAdapter.NUnitEngine.NUnitEngineAdapter.Initialize(IAdapterSettings)
4. With 2 and 3 patched locally, the driver can't load the test assembly. I skipped unreadable folders in DirectoryFinder and caught the activator's FileNotFoundException. The Debug run then got as far as loading the test assembly, and failed there:
NUnit.Engine.NUnitEngineException: Failed to load the test assembly /data/user/0/com.companyname.DroidNUnit/files/.__override__/x86_64/DroidNUnit.dll
at NUnit.Engine.Drivers.NUnitNetCore31Driver.Load(String assemblyPath, IDictionary`2 settings)
at NUnit.Engine.Runners.DirectTestRunner.LoadDriver(...)
at NUnit.Engine.Runners.MasterTestRunner.Explore(TestFilter filter)
at NUnit.VisualStudio.TestAdapter.NUnitEngine.NUnitEngineAdapter.Explore(TestFilter filter)
I stopped there, because it looks like the driver loading the test assembly from its file path into its own load context. That is a desktop assumption, not a one-line fix.
Question
The engine was built for desktop runners, so these are probably not individual bugs so much as a design question. For on-device runs, would you rather the engine learn to cope with a device (no browsable file system, assemblies not on disk), or have the adapter skip the engine on mobile and drive the NUnit framework directly, as the old nunit.xamarin runner did? I'm happy to help with either and to test on the emulator. I can also share the repro project and my two local patches if they're useful.
- Lingua principale
- C#
- Stelle
- 236
- Fork
- 165
- Merge medio
- 2g 11h
- PR unite (30g)
- 25
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di nunit/nunit-console
-
Bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
nunit/nunit-console#1913 ·
I maintainer di solito rispondono entro 1 giorno
-
Bug Needs Confirmation V3
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
nunit/nunit-console#1835 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Preparation for Console / Engine Release - Version 3.23.0Forse già presa @CharliePoole l’ha presa 22 giorni fa. ApertaDesign Decision
nunit/nunit-console#1959 · 4 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Build Up for Grabs
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
nunit/nunit-console#1958 ·
I maintainer di solito rispondono entro 1 giorno
-
Add .NET 11.0 AgentApertaBlocked Feature
Difficoltà 3/5 1-2 giorni Idoneità per principianti 52/100
nunit/nunit-console#1953 · 5 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di nunit/nunit-console
Issue simili
-
kronos:develop:queued priority:P0
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
nopSolutions/nopCommerce#8512 ·
I maintainer di solito rispondono entro 4 giorni
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
modelcontextprotocol/csharp-sdk#2061 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno