2015-10-22 34 views
0

我正在使用MSTest和命令行運行specflow測試。 項目建立沒有錯誤,但測試失敗,出現錯誤:Specflow + MSTest:測試失敗,錯誤爲「無法加載文件或程序集'MyPlugin.SpecFlowPlugin'或它的一個依賴項'

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 

任何人可以幫助我嗎?

回答

0

問題可能是您的插件dll(或其依賴關係之一)在specflow期望從其加載的位置找不到。

您可以指定位置找到應用程序的.config插件爲explained in the documentation

The following example is used to load a plugin assembly called "MyNewPlugin.SpecFlowPlugin.dll" that is located in a folder called "Binaries" that is at the same level of the current project.

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

檢查構建服務器的輸出上看到正在創建的插件DLL,並且或者適當地調整版本或配置

+0

以下行存在於App.config中' PavelAnih

0

看起來像你試圖在你的項目中加載程序集。爲了加載程序集,您必須在app.config中添加以下代碼。

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

在App.config中有步驟組件。 – PavelAnih

0

問題已解決。我已添加.testsettings文件與選中的部署複選框。部署項目 - 具有所有必需dll的bin文件夾。

相關問題