Sim*_*ens 3 sql-server unit-testing mstest visual-studio-2017 sql-server-unit-testing
将Visual Studio单元测试项添加到Visual Studio 2017中的单元测试项目时,我收到以下错误:
The reference "Microsoft.VisualStudio.QualityTools.UnitTestFramework,
Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a,
processorArchitecture=MSIL" could not be added to the project.
This wizard will continue to run, but the resulting project may not build properly.
Run Code Online (Sandbox Code Playgroud)
该项目似乎在之后构建良好,但所有sql单元测试失败并出现以下错误:
Test Name: SqlTest1
Test FullName: UnitTestProject1.SqlServerUnitTest1.SqlTest1
Test Source: c:\[path]\SqlServerUnitTest1.cs : line 34
Test Outcome: Failed
Test Duration: 0:00:00.0278356
Result StackTrace:
at System.RuntimeType.TryChangeType(Object value, Binder binder, CultureInfo culture, Boolean needsSpecialCast)
at System.RuntimeType.CheckValue(Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr)
at System.Reflection.MethodBase.CheckArguments(Object[] parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig)
at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index)
Result Message:
Unable to set TestContext property for the class
UnitTestProject1.SqlServerUnitTest1.
Error: System.ArgumentException: Object of type
'Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.TestContextImplementation'
cannot be converted to type 'Microsoft.VisualStudio.TestTools.UnitTesting.TestContext'..
Run Code Online (Sandbox Code Playgroud)
[我已经解决了这个问题,并将在下面添加我的修复作为答案,我正在创建此文档以记录其他可能会发现有用的解决方案.如果有其他人经历过这个并且可以解释原因,我仍然会感兴趣]
这似乎与自动引用的包中的测试工具的不匹配版本有关.
这是我做的修复它:
删除项目的引用Microsoft.VisualStudio.TestPlatform.TestFramework和Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions从项目中删除引用.
然后添加一个新的引用Microsoft.VisualStudio.QualityTools.UnitTestFramework.您可以在参考对话框的Assemblies - > Extensions列表中找到它.您可能会发现有两个副本,都列为版本10.1.0.0.在这种情况下,你应该检查每个的文件版本,你会发现一个是14.0.23107.0,一个是15.0.26228.0这是你想要的15.x.
更改这些参考后,一切都很好.
| 归档时间: |
|
| 查看次数: |
634 次 |
| 最近记录: |