【发布时间】: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