Specflow + MSTest:测试失败,出现错误"无法加载文件或程序集' MyPlugin.SpecFlowPlugin'或其中一个依赖"

时间:2015-10-22 16:16:13

标签: c# .net mstest specflow

我正在使用MSTest和命令行运行specflow测试。 项目构建没有错误,但测试失败并出现错误:

    Class Initialization method MyProject.SpecFiles.MyFeature.FeatureSetup threw exception. TechTalk.SpecFlow.SpecFlowException: TechTalk.SpecFlow.SpecFlowException: Unable to load plugin: MyPlugin. Please check http://go.specflow.org/doc-plugins for details. ---> System.IO.FileNotFoundException: Could not load file or assembly 'MyPlugin.SpecFlowPlugin' 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].
.
+++++++++++++++++++
STACK TRACE:
    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.RuntimePluginLoader.LoadPlugin(PluginDescriptor pluginDescriptor)
 --- End of inner exception stack trace ---
    at TechTalk.SpecFlow.Infrastructure.RuntimePluginLoader.LoadPlugin(PluginDescriptor pluginDescriptor)
   at TechTalk.SpecFlow.Infrastructure.TestRunContainerBuilder.<>c__DisplayClass3.<LoadPlugins>b__1(PluginDescriptor pd)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.<ConcatIterator>d__71`1.MoveNext()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at TechTalk.SpecFlow.Infrastructure.TestRunContainerBuilder.LoadPlugins(IRuntimeConfigurationProvider configurationProvider, ObjectContainer container)
   at TechTalk.SpecFlow.Infrastructure.TestRunContainerBuilder.CreateContainer(IRuntimeConfigurationProvider configurationProvider)
   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 MyProject.SpecFiles.MyFeature.FeatureSetup(TestContext testContext) in d:\Jenkins\workspace\MyProject\SpecFiles\MyFeature.feature.cs:line 0

任何人都可以帮助我吗?

3 个答案:

答案 0 :(得分:0)

问题可能是你的插件dll(或其中一个依赖项)在specflow期望加载它的地方找不到。

您可以指定一个位置,以便在app .config中找到该插件explained in the documentation

  

以下示例用于加载名为“MyNewPlugin.SpecFlowPlugin.dll”的插件程序集,该程序集位于名为“Binaries”的文件夹中,该文件夹位于当前项目的同一级别。

<specFlow>
    <plugins>
        <add name="MyNewPlugin" path="..\Binaries" />
    </plugins>
</specFlow>

检查构建服务器上的输出以查看正在创建插件dll的位置,并相应地调整构建或配置

答案 1 :(得分:0)

看起来您正在尝试在项目中加载程序集。要加载程序集,您必须在app.config中添加以下代码。

<stepAssemblies>
     <stepAssembly assembly="{name-of-assembly-containing-bindgins}" /> 
</stepAssemblies>

答案 2 :(得分:0)

问题解决了。我添加了.testsettings文件,并选中了Deployment复选框。部署项目 - 包含所有必需dll的bin文件夹。