Visual studio 2010 单元测试适配器引发异常:无法加载一个或多个请求的类型
我正在尝试从Visual Studio 2010命令提示符运行SpecFlow测试,收到一条相当迟钝的错误消息:Visual studio 2010 单元测试适配器引发异常:无法加载一个或多个请求的类型,visual-studio-2010,mstest,specflow,Visual Studio 2010,Mstest,Specflow,我正在尝试从Visual Studio 2010命令提示符运行SpecFlow测试,收到一条相当迟钝的错误消息: Test method Blah.Dee.Blah threw exception: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.VisualStudio.TestTools.UITest.Extension, Version=11.0.0.0, Culture=neutra
Test method Blah.Dee.Blah threw exception:
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.VisualStudio.TestTools.UITest.Extension, Version=11.0.0.0, Culture=neutral, PublicKeyToken=...' or one of its dependencies. The system cannot find the file specified.WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
TestCleanup method Blah.Dee.Blah.ScenarioTearDown threw exception. BoDi.ObjectContainerException: BoDi.ObjectContainerException: Interface cannot be resolved: SpecBind.BrowserSupport.IBrowser.
单元测试适配器引发异常:
无法加载一个或多个请求的类型。有关详细信息,请检索LoaderExceptions属性
有关我的VS2010项目设置的一些信息:
C:\path\to\bin\Debug> mstest /testcontainer:MyTests.dll /test:SpecFlowFeatureName
Loading MyTests.dll
Starting Execution...
Results Top Level Tests
-------- ------------------
Failed ...
Failed ...
Failed ...
...
- Windows 7 Enterprise,64位(版本6.1.7601 Service Pack 1 Build 7601)
- Visual Studio 2010高级版(v10.0.40219.1 SP1Rel)
- 使用编码的UI测试
- 使用SpecFlow 1.9.0,它将委托给CodedUI测试API
- MSTest
- .NET v4.0.30319
- 整个解决方案是编译为32位代码(我的同事仍在使用XP)
copy $(SolutionDir)packages\SpecBind.1.2.1.71\lib\net45\SpecBind.dll $(TargetDir)
copy $(SolutionDir)packages\SpecBind.CodedUI.1.2.1.71\lib\net45\SpecBind.CodedUI.dll $(TargetDir)
没有它,mstest不知何故无法加载许多SpecFlow程序集
测试项目App.config的相关部分
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="specFlow" type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow" />
<section name="specBind" type="SpecBind.Configuration.ConfigurationSectionHandler, SpecBind" />
</configSections>
<connectionStrings>
...
</connectionStrings>
<specFlow>
<!-- For additional details on SpecFlow configuration options see http://go.specflow.org/doc-config -->
<unitTestProvider name="MsTest" generatorProvider="Specflow.CodedUI.MsTestCodedUiGeneratorProvider, Specflow.CodedUI" runtimeProvider="TechTalk.SpecFlow.UnitTestProvider.MsTest2010RuntimeProvider, TechTalk.SpecFlow" />
<stepAssemblies>
<!-- This attribute is required in order to use StepArgument Transformation as described here;
https://github.com/marcusoftnet/SpecFlow.Assist.Dynamic/wiki/Step-argument-transformations -->
<stepAssembly assembly="SpecFlow.Assist.Dynamic" />
<stepAssembly assembly="SpecBind" />
</stepAssemblies>
</specFlow>
<specBind>
<browserFactory provider="SpecBind.CodedUI.CodedUIBrowserFactory, SpecBind.CodedUI" browserType="IE" />
<!-- For additional details on SpecBind configuration options see the project site. -->
</specBind>
</configuration>
我一直在到处寻找解决方案,我一直在寻找VS2008的引用和禁用代码覆盖率。我有VS2010,本地测试设置中未启用代码覆盖率
Windows事件日志查看器
在我的Windows事件日志查看器中搜索之后,我终于找到了更多信息(我听说有人抱怨他们找不到带有此错误的堆栈跟踪--请查看事件查看器)
我不知道如何解决这个错误。当我右键单击编辑器中加载的.feature文件并选择“运行SpecFlow场景…”时,SpecFlow测试可以在Visual Studio内部正常运行,但我无法从命令行运行它们
有什么想法或其他信息我可以发布吗
作为旁注,这源于我先前的问题:
更新#1
我做了更多的探索,发现了这篇博文:。我检查了本地测试设置,它强制测试以32位运行
现在使用此命令:
mstest /testcontainer:MyTests.dll /testsettings:"..\..\..\Local.testsettings"
错误消息:
Test method Blah.Dee.Blah threw exception:
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.VisualStudio.TestTools.UITest.Extension, Version=11.0.0.0, Culture=neutral, PublicKeyToken=...' or one of its dependencies. The system cannot find the file specified.WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
TestCleanup method Blah.Dee.Blah.ScenarioTearDown threw exception. BoDi.ObjectContainerException: BoDi.ObjectContainerException: Interface cannot be resolved: SpecBind.BrowserSupport.IBrowser.
更新#2
我删除了对Microsoft.VisualStudio.TestTools.UITest.Extension的引用,并将其重新添加。清洁。重建。再次运行相同的命令。仍然得到相同的错误
出于某种原因,它试图将Microsoft.VisualStudio.TestTools.UITest.Extension程序集加载为版本11,我的机器上安装了版本10。我正在努力跟踪指定此版本的位置,以便可以更改它。在上面@jessehouwing的评论的帮助下,我已经修复了此问题。我遇到了两个问题 我最初引用的错误实际上是由mstest试图在64位进程(QTAgent.exe)中运行测试引起的。我需要它作为32位进程运行,因为该项目在我的64位Windows7机器上编译为32位代码 在Visual Studio 2010中:
mstest /testcontainer:foo.dll /testsettings:"path/to/solution/local.testsettings" /test:SpecFlowFeatureName
- 强制mstest在32位进程中运行,并从命令行引用此local.testsettings文件
- 删除了对SpecBind的所有引用,因为我之前有点不高兴,安装了一个与.NET运行时不兼容的包
至于您的32位问题,您可能应该将项目的CPU配置设置为
AnyCPU
,通常不需要将其修复为x86,除非您依赖于本机方法,或者您正在引用其他专门设置为使用x86作为其目标体系结构的程序集。以防其他人遇到这种情况,我认为这是因为启用了代码覆盖率。禁用它解决了以下问题:
- 打开.testsettings文件
- 在“测试设置”下,单击“数据和诊断”
- 取消选中“代码覆盖率”
- 点击“应用”
- 这太麻烦了
我在我的测试机器上安装了Visual Studio 2015的测试代理,因为我们计划使用它——而在我的本地机器上,我安装了2013。测试在本地使用MsBuild运行得如此完美,以至于我无法理解会发生什么,因为我一直认为Microsoft始终保持向后兼容
测试服务器上的MsBuild未能提供有关缺少哪些程序集的任何信息(我添加了Newtonsoft.Json只是因为它最初抱怨,但此后我再也没有看到缺少的任何其他程序集的名称)。错误消息被截断,stacktrace和debugtrace选项从未工作
一旦我在测试机上安装了Visual Studio 2013的测试代理,它就运行得很好。我开始这么做了