我有一个使用SpecFlow 1.8.1和mstest的VS2010单元测试项目。为了让SpecFlow单元测试工作,我已经完成了以下步骤:
我在我的项目中添加了以下文件的引用:
Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll TechTalk.SpecFlow.dll
请注意,TechTalk.SpecFlow.dll已经添加到我的项目中,并且引用指向该文件。
我将TechTalk.SpecFlow.dll引用的“复制到本地”属性设置为True。
我还添加了一个App.Config,指定了“MsTest.2010”作为提供程序,并重新生成了所有SpecFlow特性的代码。
在我的VS2010中一切正常,在SpecFlow测试运行程序和mstest测试运行程序中都可以成功运行测试。但是当我尝试在TFS 2008中运行mstests(使用.vsmdi测试列表文件)时,它会失败并抛出以下异常:
Class Initialization method MyNamespace.MyTestFeature.FeatureSetup threw exception.
System.Configuration.ConfigurationErrorsException:
System.Configuration.ConfigurationErrorsException: An error occurred creating the
configuration section handler for specFlow: Could not load file or assembly
'TechTalk.SpecFlow' or one of its dependencies. The system cannot find the file
specified. (D:\Projects\TestProject\TestResults\administrator_MYPC 2012-06-27
18_30_05_Any CPU_Debug\Out\TestProject.DLL.config line 4) --->
System.IO.FileNotFoundException: Could not load file or assembly 'TechTalk.SpecFlow'
or one of its dependencies. The system cannot find the file specified.
请注意,TFS成功构建了项目,并在同一项目中运行其他单元测试(普通的 mstests,而不是 SpecFlow),没有出现问题。它只是在 SpecFlow 测试运行时失败了。
那么我做错了什么?
编辑:我的 App.Config 文件内容如下:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section
name="specFlow"
type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow"/>
</configSections>
<specFlow>
<unitTestProvider name="MsTest.2010" />
<runtime detectAmbiguousMatches="true"
stopAtFirstError="false"
missingOrPendingStepsOutcome="Inconclusive" />
<trace traceSuccessfulSteps="true"
traceTimings="false"
minTracedDuration="0:0:0.1" />
</specFlow>
</configuration>