Visual studio 运行测试时加载文件或程序集SpecFlow.Assist.Dynamic失败

Visual studio 运行测试时加载文件或程序集SpecFlow.Assist.Dynamic失败,visual-studio,visual-studio-2013,coded-ui-tests,specflow,assemblybinding,Visual Studio,Visual Studio 2013,Coded Ui Tests,Specflow,Assemblybinding,我在Visual Studio 2013中有一个CodedUI测试项目。按照说明将SpecFlow与CodedUI API集成后,我在功能设置中遇到以下错误(程序集绑定日志记录已打开) 测试名称:TheWelcomeScreen 测试全名:(…)功能。欢迎进入屏幕 测试源:c:\path\to\My.feature:第6行 测试结果:失败 测试持续时间:0:00:00 结果消息: 类初始化方法(…)Feature.FeatureSetup引发异常。System.IO.FileNotFoundEx

我在Visual Studio 2013中有一个CodedUI测试项目。按照说明将SpecFlow与CodedUI API集成后,我在
功能设置中遇到以下错误(程序集绑定日志记录已打开)

测试名称:TheWelcomeScreen

测试全名:(…)功能。欢迎进入屏幕

测试源:c:\path\to\My.feature:第6行

测试结果:失败

测试持续时间:0:00:00

结果消息: 类初始化方法(…)Feature.FeatureSetup引发异常。System.IO.FileNotFoundException:System.IO.FileNotFoundException:无法加载文件或程序集“SpecFlow.Assist.Dynamic,Version=1.0.2.0,Culture=neutral”或其依赖项之一。系统找不到指定的文件

=== Pre-bind state information ===

LOG: DisplayName = SpecFlow.Assist.Dynamic, Version=1.0.2.0, Culture=neutral
(Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: SpecFlow.Assist.Dynamic, Version=1.0.2.0, Culture=neutral | Domain ID: 2
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:/Path/To/Current/TestResults/Directory/Out
LOG: Initial PrivatePath = NULLCalling assembly : TechTalk.SpecFlow, Version=1.9.0.77, Culture=neutral, PublicKeyToken=0778194805d6db41.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Path\To\Current\TestResults\Directory\Out\BWE.Tests.DLL.config
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:/Path/To/Current/TestResults/Directory/Out/SpecFlow.Assist.Dynamic.DLL.
LOG: Attempting download of new URL file:///C:/Path/To/Current/TestResults/Directory/Out/SpecFlow.Assist.Dynamic/SpecFlow.Assist.Dynamic.DLL.
LOG: Attempting download of new URL file:///C:/Path/To/Current/TestResults/Directory/Out/SpecFlow.Assist.Dynamic.EXE.
LOG: Attempting download of new URL file:///C:/Path/To/Current/TestResults/Directory/Out/SpecFlow.Assist.Dynamic/SpecFlow.Assist.Dynamic.EXE.
结果跟踪:

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.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection)
at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.Load(String assemblyString)
at TechTalk.SpecFlow.Infrastructure.BindingAssemblyLoader.Load(String assemblyName)
at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
at TechTalk.SpecFlow.Infrastructure.TestRunnerFactory.Create(Assembly testAssembly)
at TechTalk.SpecFlow.TestRunnerManager.CreateTestRunner(TestRunnerKey key)
at TechTalk.SpecFlow.TestRunnerManager.GetTestRunner(TestRunnerKey key)
at TechTalk.SpecFlow.TestRunnerManager.GetTestRunner(Assembly testAssembly, Boolean async)
at TechTalk.SpecFlow.TestRunnerManager.GetTestRunner()
at (...)Feature.FeatureSetup(TestContext testContext) in c:\path\to\My.feature.cs:line 0
此解决方案的My
packages.config
文件:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="AutoMapper" version="3.3.0" targetFramework="net40" />
  <package id="CompareNETObjects" version="3.01.0.0" targetFramework="net40" />
  <package id="ImpromptuInterface" version="6.2.2" targetFramework="net40" />
  <package id="SpecFlow" version="1.9.0" targetFramework="net40" />
  <package id="SpecFlow.Assist.Dynamic" version="1.0.2" targetFramework="net40" />
</packages>

在SpecFlow.Assist.Dynamic DLL的“属性”中,
CopyLocal
设置被设置为
true
。构建解决方案后,
bin\Debug
文件夹中有
SpecFlow.Assist.Dynamic.dll
,但是
TestResults
文件夹中当前测试运行的文件夹不包含此dll。它确实包含以下DLL:

  • 我的项目的DLL
  • AutoMapper.dll
  • KellermanSoftware.Compare-Net-Objects.dll
  • TechTalk.SpecFlow.dll

我已打开和关闭Visual Studio,卸载并重新安装NuGet软件包,在本地删除软件包源,清理、重建、重新启动,手动删除
bin\Debug
文件夹并重建。。。这个名单还有很多。我仍然会遇到同样的异常。

我不知道它是否是设计的,但MSTest不会将程序集部署到测试文件夹,除非测试或测试代码中至少使用了该程序集中的一种类型。因此,如果您正在通过反射从和程序集实例化类型,那么您将遇到问题

一直是

简单的解决方案是做以下两件事之一:

  • 在测试中使用相关程序集中的虚拟类型。只需执行redendant
    var dummy=new TheType()
  • 使用部署项复制dll。我认为这不太好,因为您可能无法部署它,除非您正在运行一个包含部署项的测试,这可能意味着您需要多次使用该属性,尽管我不是100%确定

您是否在测试中实际使用了参考?这听起来像是通过切换到NUnit而不是MSTest来修复的,或者通过在其中一个测试中添加该dll作为部署项来确保MSTest将其复制到测试运行目录。这看起来像是一个黑客,但我不知道为什么它不能开箱即用…因为事实证明我没有使用SpecFlow.Assist.Dynamic。我删除了NuGet软件包,现在一切正常。这并不是一个真正的“解决方案”,但很有效,因为我没有使用它。如果您使用了它,我想MSBuild会将它包含在测试部署的文件中?我们以前也看到过类似的情况,我们必须在程序集中放置对类的虚拟引用,以便让VS将其与测试一起部署。我只是通过Visual Studio进行编译,而不是从命令行使用MsBuild。SpecFlow.Assist.Dynamic.dll文件不在测试目录中。但它位于bin\Debug目录中。抱歉,这意味着MSTest不是MSBuild。根据我的经验,MSTest只部署具有测试代码或被测试代码使用的类的文件,因此即使引用了程序集,如果您仅通过反射使用类型,也不会部署assmbly