【问题标题】:How remove rogue NUnit test adapter from Visual Studio 2017 netcore environment?如何从 Visual Studio 2017 netcore 环境中删除流氓 NUnit 测试适配器?
【发布时间】:2018-09-03 21:03:13
【问题描述】:

以下在我的计算机上失败,但对同事有效。有谁知道在 VS / .NET 生态系统中哪里可以修复我的机器? 我希望避免重新安装... :( 为时已晚,重新安装解决了问题...

问题:无论我选择哪个单元测试库,我的计算机似乎都在运行流氓 NUnit 测试适配器,这似乎干扰了 VS 运行单元测试的能力。我有 ReSharper(它没有发现任何测试),但我已暂停它以尽量减少问题。

MSTest

只需在新目录中运行dotnet new mstest,然后运行dotnet test 即可使模板“TestMethod1”测试通过,测试运行成功。但是,在 Visual Studio Pro 2017 中打开项目,然后单击 Test Explorer 窗口中的 Run All 会产生以下测试输出:

[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

只需在新目录中运行dotnet new nunit,然后运行dotnet test 即可使模板“Test1”测试通过,测试运行成功。但是,在 Visual Studio Pro 2017 中打开项目,然后单击 Test Explorer 窗口中的 Run All 会产生以下测试输出(我已启用登录 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

只需在新目录中运行dotnet new xunit,然后运行dotnet test 即可使模板“Test1”测试通过,测试运行成功。但是,在 Visual Studio Pro 2017 中打开项目,然后单击 Test Explorer 窗口中的 Run All 会产生以下测试输出:

[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) ==========

研究

  • xUnit 团队不同意核心编译器团队关于自动前滚行为:https://github.com/xunit/xunit/issues/1573——然而,虽然我可以通过 csproj 修改“修复”dotnet xunit,但上述错误仍然发生在 VS 中。此外,该问题独立于 xUnit 发生,因此这似乎是其他问题
  • 启用绑定失败日志记录:How to enable assembly bind failure logging (Fusion) in .NET - 这在 NUnit 版本中提供了其他信息,例如可能需要一个 app.config 设置,它可能会以某种方式改变 .NET 生态系统,但我不确定要做什么添加。添加 app.config 文件没有产生任何变化。
  • 许多其他搜索几乎都是在黑暗中拍摄的,不知道要搜索什么...:(

【问题讨论】:

    标签: unit-testing visual-studio-2017 .net-core


    【解决方案1】:

    我继续卸载/重新安装,在这种情况下“修复”了问题。如何在重新安装之外解决此问题的根本问题仍然存在。

    我将不选中此解决方案,以防将来有人可以回答问题而不是解决问题。

    【讨论】:

      【解决方案2】:

      这对我来说是版本冲突;该解决方案引用了 NUnit v2.x,但 VS2017 适配器​​扩展是 NUnit 3 测试适配器,它们不兼容!

      提示是输出调试出现“NUnit Adapter 3.x: Test execution started”,然后找不到任何测试。

      要解决此问题,您必须卸载 NUnit 3 测试适配器(通过工具 -> 扩展和更新),然后关闭 VS2017 以允许将其删除。等到您看到 VSIX 安装程序窗口出现并确认它已被卸载。

      现在通过运行 VS2017 并安装(再次通过工具 -> 扩展和更新)安装 NUnit 2 测试适配器,您需要再次关闭 VS2017 以允许 VSIX 安装扩展。

      最后,您应该能够运行 VS2017 并加载您的解决方案,然后重新构建解决方案以查找所有测试用例。

      现在您应该可以运行测试了。

      【讨论】:

        【解决方案3】:

        对我来说,问题是其中一个测试扩展被禁用。我启用了所有包含测试的扩展。 (工具 --> 扩展和更新)

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2021-11-30
          • 1970-01-01
          • 2018-11-24
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多