Gre*_*rdt 12 mstest visual-studio-2010 specflow
我试图从Visual Studio 2010命令提示符运行SpecFlow测试,我收到一个相当迟钝的错误消息:
单元测试适配器引发异常:无法加载一个或多个请求的类型.检索LoaderExceptions属性以获取更多信息.
有关我的VS2010项目设置的一些信息:
我有一个post-build事件,它将我的NuGet包目录中的一些DLL文件复制到目标目录:
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)
Run Code Online (Sandbox Code Playgroud)
没有这个,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>
Run Code Online (Sandbox Code Playgroud)
我用来启动测试的命令:
C:\path\to\bin\Debug> mstest /testcontainer:MyTests.dll /test:SpecFlowFeatureName
Loading MyTests.dll
Starting Execution...
Results Top Level Tests
-------- ------------------
Failed ...
Failed ...
Failed ...
...
Run Code Online (Sandbox Code Playgroud)
我一直在寻找解决方案的高低,而我一直在寻找的是对VS2008的引用和禁用代码覆盖率.我有VS2010并且我的本地测试设置中未启用代码覆盖率.
Windows事件日志查看器
在我的Windows事件日志查看器中生根后,我终于遇到了更多信息(我听说有人抱怨他们找不到这个错误的堆栈跟踪 - 请查看事件查看器)
The description for Event ID 0 from source VSTTExecution cannot be found. Either the component that raises this event is not installed on your local computer or the installation is corrupted. You can install or repair the component on the local computer.
If the event originated on another computer, the display information had to be saved with the event.
The following information was included with the event:
(QTAgent32.exe, PID 6920, Thread 213) Unit Test Adapter threw exception: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeModule.GetTypes()
at System.Reflection.Assembly.GetTypes()
at Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestExecuter.GetAssemblyInfo(Assembly assembly)
at Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestExecuter.GetTypeInfo(Type type, Boolean checkAlreadyExaminedType)
at Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestExecuter.ResolveMethods()
at Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestExecuter.Initialize(UnitTestResult result, UnitTestRunner runner, ConsoleOutputRedirector redirector)
at Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestRunner.Run(UnitTestElement test, ITestContext testContext, Boolean isLoadTest, Boolean useMultipleCpus)
the message resource is present but the message is not found in the string/message table
Run Code Online (Sandbox Code Playgroud)
我不知道如何解决这个错误.当我右键单击编辑器中加载的.feature文件并选择"运行SpecFlow场景..."但我无法从命令行运行它们时,SpecFlow测试在Visual Studio内运行正常.
我可以发布的任何想法或其他信息?
作为旁注,这源于我之前的问题:如何使用MSTest从命令行运行SpecFlow场景?
更新#1
我做了一些更多的探索,发现这篇博文:MSTest和64bit.我检查了我的本地测试设置,它强制测试以32位运行.
现在使用此命令:
mstest /testcontainer:MyTests.dll /testsettings:"..\..\..\Local.testsettings"
Run Code Online (Sandbox Code Playgroud)
错误信息:
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.
Run Code Online (Sandbox Code Playgroud)
更新#2
我删除了对Microsoft.VisualStudio.TestTools.UITest.Extension的引用并将其添加回来.清洗.重修.再次执行相同的命令.仍然得到同样的错误.
出于某种原因,它试图将Microsoft.VisualStudio.TestTools.UITest.Extension程序集加载为版本11,并且我的计算机上安装了版本10.我正在尝试追踪指定此版本的位置,以便我可以更改它.
万一其他人遇到这个,对我来说这是因为代码覆盖率已启用.禁用它解决了问题:
http://blogs.msdn.com/b/danielvl/archive/2010/02/16/enable-code-coverage-in-visual-studio.aspx
在@jessehouwing 上面的评论的帮助下,我已经解决了这个问题。我遇到了两个问题。
我最初引用的错误实际上是由 mstest 尝试在 64 位进程 (QTAgent.exe) 中运行测试引起的。我需要它作为 32 位进程运行,因为该项目在我的 64 位 Windows 7 计算机上编译为 32 位代码。
在 Visual Studio 2010 中:
在 Visual Studio 命令提示符中,通过引用 Visual Studio 生成的 local.testsettings 文件来运行测试:
mstest /testcontainer:foo.dll /testsettings:"path/to/solution/local.testsettings" /test:SpecFlowFeatureName
Run Code Online (Sandbox Code Playgroud)我遇到的第二个问题是我自己的错。早些时候,我正在尝试编码 UI 测试和 SpecFlow,并安装了SpecBind,它为我的测试项目在 App.config 中添加了一堆设置。这个NuGet包仅适用于.NET 4.5,我们使用.NET 4.0。我从 App.config 中删除了 NuGet 包和设置,进行了清理和重建。这完全解决了这个问题。
简而言之,我:
| 归档时间: |
|
| 查看次数: |
15200 次 |
| 最近记录: |