I had this exact problem where I had 3 separate test projects, 2 of them ran without issue and the third one never ran, even if I tried to run the tests individually. There was no easy way to see what the reason was. The tests would not run on our YAML build pipeline in DevOps either.
Consolidate NuGet versions
First and foremost I would ensure your NuGet versions are consolidated for NUnit
and NUnit3TestAdapter
, to do this, right click the solution and click Manage NuGet packages for solution...
go across to the Consolidate
tab.
In my case the NuGet packages for NUnitTestAdapter
were not aligned for the project that would not run, I consolidated those versions and then rebuilt the solution, ran all tests and now all 3 projects run successfully.
Check Output -> Tests
If the above doesn't work then I would suggest this step as it should output the exception being thrown by the test runner.
On the top bar select View
and then Output
(default shortcut Ctrl+Shift+U
). Once this has opened change the drop-down for Show output from:
to Tests
, this should now give you the outputted logs from the test runner.
In my case the logs looked like this:
Multiple versions of same extension found. Selecting the highest version.
NUnit3.TestAdapter : 4.3.0.0
Aborting test discovery because a test run was requested.
Discovery of tests cancelled.
The active test discovery was aborted.
========== Test discovery aborted: 0 Tests found in 3.9 sec ==========
Building Test Projects
Starting test discovery for requested test run
========== Starting test discovery ==========
Multiple versions of same extension found. Selecting the highest version.
NUnit3.TestAdapter : 4.3.0.0
NUnit Adapter 4.3.0.0: Test discovery starting
Exception System.UnauthorizedAccessException, Exception thrown discovering tests in C:\Source\MainSolution\TestProject3.Tests\bin\Debug\net462\TestProject3.Tests.dll
Access to the path 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\InternalTrace.31504.log' is denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at NUnit.Engine.Internal.InternalTraceWriter..ctor(String logPath)
at NUnit.Engine.Internal.InternalTrace.Initialize(String logName, InternalTraceLevel level)
at NUnit.Engine.TestEngine.Initialize()
at NUnit.Engine.TestEngine.GetRunner(TestPackage package)
at NUnit.VisualStudio.TestAdapter.NUnit3TestDiscoverer.DiscoverTests(IEnumerable`1 sources, IDiscoveryContext discoveryContext, IMessageLogger messageLogger, ITestCaseDiscoverySink discoverySink) in D:\repos\NUnit\nunit3-vs-adapter\src\NUnitTestAdapter\NUnit3TestDiscoverer.cs:line 82
NUnit Adapter 4.3.0.0: Test discovery complete
No test is available in C:\Source\MainSolution\TestProject3.Tests\bin\Debug\net462\TestProject3.Tests.dll. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.
The exception is being thrown by NUnit3TestDiscoverer.cs
, at the start of the exception it mentions Multiple versions of same extension found. Selecting the highest version. NUnit3.TestAdapter : 4.3.0.0
There might be other exceptions being thrown in the logs, but in my case it was just the misalignment of NuGet versions.
async void
test method rather thanasync Task
– Molybdic