2

The following fails on my computer, but works on a co-workers. Does anyone know where in the VS / .NET ecosystem to look to fix my machine? I'm hoping to avoid a reinstall... :( too late, reinstall fixed the problem...

The problem: it looks like my computer has a rogue NUnit test adapter being run, regardless of which unit test library I choose, and this appears to interfere with VS's ability to run unit tests. I have ReSharper (which did not identify any tests), but I have suspended it to minimize the problem.

MSTest

Simply running dotnet new mstest in a new directory, then running dotnet test causes the template "TestMethod1" test to pass, and the test run is successful. However, opening the project in Visual Studio Pro 2017, and clicking on Run All in the Test Explorer window yields the following Tests Output:

[3/25/2018 10:40:48 AM Informational] ------ Load Playlist started ------
[3/25/2018 10:40:48 AM Informational] ========== Load Playlist finished (0:00:00.0620084) ==========
[3/25/2018 10:41:23 AM Informational] ------ Run test started ------
[3/25/2018 10:41:26 AM Informational] NUnit Adapter 3.10.0.21: Test execution started
[3/25/2018 10:41:26 AM Informational] Running all tests in C:\git\MySandbox\testtest\bin\Debug\netcoreapp2.0\testtest.dll
[3/25/2018 10:41:26 AM Informational] NUnit couldn't find any tests in C:\git\MySandbox\testtest\bin\Debug\netcoreapp2.0\testtest.dll
[3/25/2018 10:41:26 AM Informational] NUnit Adapter 3.10.0.21: Test execution complete
[3/25/2018 10:41:26 AM Warning] [MSTest][Discovery][C:\git\MySandbox\testtest\bin\Debug\netcoreapp2.0\testtest.dll] Unable to load types from the test source 'C:\git\MySandbox\testtest\bin\Debug\netcoreapp2.0\testtest.dll'. Some or all of the tests in this source may not be discovered.
[3/25/2018 10:41:26 AM Warning] No test is available in C:\git\MySandbox\testtest\bin\Debug\netcoreapp2.0\testtest.dll. Make sure that installed test discoverers & executors, platform & framework version settings are appropriate and try again.
[3/25/2018 10:41:26 AM Informational] ========== Run test finished: 0 run (0:00:02.9689937) ==========

NUnit

Simply running dotnet new nunit in a new directory, then running dotnet test causes the template "Test1" test to pass, and the test run is successful. However, opening the project in Visual Studio Pro 2017, and clicking on Run All in the Test Explorer window yields the following Tests Output (I have enabled logging in Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion\EnableLog):

[3/25/2018 10:59:17 AM Informational] ------ Run test started ------
[3/25/2018 10:59:18 AM Informational] NUnit Adapter 3.10.0.21: Test execution started
[3/25/2018 10:59:18 AM Informational] Running all tests in C:\git\MySandbox\testtest\bin\Debug\netcoreapp2.0\testtest.dll
[3/25/2018 10:59:18 AM Warning] Exception NUnit.Engine.NUnitEngineException, Exception thrown executing tests in C:\git\MySandbox\testtest\bin\Debug\netcoreapp2.0\testtest.dll
[3/25/2018 10:59:18 AM Warning] An exception occurred in the driver while loading tests.
[3/25/2018 10:59:18 AM Warning]    at NUnit.Engine.Runners.DirectTestRunner.LoadDriver(IFrameworkDriver driver, String testFile, TestPackage subPackage)
   at NUnit.Engine.Runners.DirectTestRunner.LoadPackage()
   at NUnit.Engine.Runners.TestDomainRunner.LoadPackage()
   at NUnit.Engine.Runners.DirectTestRunner.EnsurePackageIsLoaded()
   at NUnit.Engine.Runners.DirectTestRunner.Explore(TestFilter filter)
   at NUnit.Engine.Runners.MasterTestRunner.Explore(TestFilter filter)
   at NUnit.VisualStudio.TestAdapter.NUnit3TestExecutor.RunAssembly(String assemblyPath, TestFilter filter)
[3/25/2018 10:59:18 AM Warning] Innerexception: System.IO.FileNotFoundException: Could not load file or assembly 'nunit.framework' or one of its dependencies. The system cannot find the file specified.
File name: 'nunit.framework'
   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Activator.CreateInstance(String assemblyString, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo, StackCrawlMark& stackMark)
   at System.Activator.CreateInstance(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo)
   at System.AppDomain.CreateInstance(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityAttributes)
   at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityAttributes)
   at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityAttributes)
   at NUnit.Engine.Drivers.NUnit3FrameworkDriver.CreateObject(String typeName, Object[] args)
   at NUnit.Engine.Drivers.NUnit3FrameworkDriver.Load(String testAssemblyPath, IDictionary`2 settings)
   at NUnit.Engine.Runners.DirectTestRunner.LoadDriver(IFrameworkDriver driver, String testFile, TestPackage subPackage)

=== Pre-bind state information ===
LOG: DisplayName = nunit.framework
 (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: nunit.framework | Domain ID: 4
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/git/MySandbox/testtest/bin/Debug/netcoreapp2.0/
LOG: Initial PrivatePath = NULL
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Configuration file C:\git\MySandbox\testtest\bin\Debug\netcoreapp2.0\testtest.dll.config does not exist.
LOG: No application configuration file found.
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/git/MySandbox/testtest/bin/Debug/netcoreapp2.0/nunit.framework.DLL.
LOG: Attempting download of new URL file:///C:/git/MySandbox/testtest/bin/Debug/netcoreapp2.0/nunit.framework/nunit.framework.DLL.
LOG: Attempting download of new URL file:///C:/git/MySandbox/testtest/bin/Debug/netcoreapp2.0/nunit.framework.EXE.
LOG: Attempting download of new URL file:///C:/git/MySandbox/testtest/bin/Debug/netcoreapp2.0/nunit.framework/nunit.framework.EXE.

[3/25/2018 10:59:18 AM Informational] NUnit Adapter 3.10.0.21: Test execution complete
[3/25/2018 10:59:18 AM Warning] No test is available in C:\git\MySandbox\testtest\bin\Debug\netcoreapp2.0\testtest.dll. Make sure that installed test discoverers & executors, platform & framework version settings are appropriate and try again.
[3/25/2018 10:59:18 AM Informational] ========== Run test finished: 0 run (0:00:01.2349998) ==========

xUnit

Simply running dotnet new xunit in a new directory, then running dotnet test causes the template "Test1" test to pass, and the test run is successful. However, opening the project in Visual Studio Pro 2017, and clicking on Run All in the Test Explorer window yields the following Tests Output:

[3/25/2018 11:03:06 AM Informational] ------ Run test started ------
[3/25/2018 11:03:07 AM Informational] NUnit Adapter 3.10.0.21: Test execution started
[3/25/2018 11:03:07 AM Informational] Running all tests in C:\git\MySandbox\testtest\bin\Debug\netcoreapp2.0\testtest.dll
[3/25/2018 11:03:07 AM Informational] NUnit couldn't find any tests in C:\git\MySandbox\testtest\bin\Debug\netcoreapp2.0\testtest.dll
[3/25/2018 11:03:07 AM Informational] NUnit Adapter 3.10.0.21: Test execution complete
[3/25/2018 11:03:08 AM Error] [xUnit.net 00:00:00.1588321] testtest: Catastrophic failure: System.TypeInitializationException: The type initializer for 'Xunit.DiaSession' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Reflection.TypeExtensions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
   at Xunit.DiaSession..cctor()
   --- End of inner exception stack trace ---
   at Xunit.DiaSession..ctor(String assemblyFileName)
   at Xunit.DiaSessionWrapper..ctor(String assemblyFilename)
   at Xunit.XunitFrontController..ctor(AppDomainSupport appDomainSupport, String assemblyFileName, String configFileName, Boolean shadowCopy, String shadowCopyFolder, ISourceInformationProvider sourceInformationProvider, IMessageSink diagnosticMessageSink)
   at Xunit.Runner.VisualStudio.VsTestRunner.RunTestsInAssembly(IRunContext runContext, IFrameworkHandle frameworkHandle, LoggerHelper logger, TestPlatformContext testPlatformContext, IMessageSinkWithTypes reporterMessageHandler, AssemblyRunInfo runInfo)
[3/25/2018 11:03:08 AM Warning] No test is available in C:\git\MySandbox\testtest\bin\Debug\netcoreapp2.0\testtest.dll. Make sure that installed test discoverers & executors, platform & framework version settings are appropriate and try again.
[3/25/2018 11:03:08 AM Informational] ========== Run test finished: 0 run (0:00:01.8422737) ==========

Research

  • xUnit team disagrees with core compiler team about auto roll forward behavior: https://github.com/xunit/xunit/issues/1573 -- however, while I can "fix" dotnet xunit with a csproj modification, the above error still happens in VS. Also, the problem happens independently of xUnit, so this appears to be something else
  • Enabling bind failure logging: How to enable assembly bind failure logging (Fusion) in .NET -- this gave additional information in the NUnit version, such as possibly needing an app.config setting which could alter the .NET ecosystem in some way, but I'm not sure what to add. Adding an app.config file yielded no change.
  • numerous other searches pretty much shooting in the dark, not sure what to search for... :(
chryosolo
  • 363
  • 2
  • 11

3 Answers3

1

I proceeded to uninstall / reinstall, and in this case that "fixed" the problem. The underlying question of how to fix this outside of a reinstall still stands.

I will leave this solution unchecked in case someone in the future can answer the question instead of working around it.

chryosolo
  • 363
  • 2
  • 11
1

This was a version conflict for me; the solution was referencing NUnit v2.x but the VS2017 adapter extension was NUnit 3 Test adapter, and they're not compatible!

The hint was that the output debug comes up with "NUnit Adapter 3.x: Test execution started" and then finds no tests.

To resolve, you must uninstall the NUnit 3 Test Adapter (through Tools -> Extensions and Updates) and then close VS2017 to allow it to be removed. Wait until you see the VSIX installer window appear and confirm it is uninstalled.

Now install the NUnit 2 Test Adapter by running VS2017 and installing (again through Tools -> Extensions and Updates) and once again you will need to close VS2017 to allow VSIX to install the extension.

Finally you should be able to run VS2017 and load your solution then Rebuild Solution to find all the test cases.

Now you should be able to run your tests.

antonye
  • 41
  • 5
0

for me, the problem was that one of the test extensions was disabled. I enabled all extensions that had the test in it. (tools --> extensions and updates)

Mptje
  • 1,371
  • 1
  • 8
  • 4