如何让SpecFlow使用xUnit.net作为测试运行器

时间:2010-04-27 16:09:44

标签: xunit.net specflow

我正在尝试使用xUnit.net作为SpecFlow的测试运行器。官方下载区域的SpecFlow 1.2二进制文件不包含xUnit.net提供程序,但GitHub上的主分支有一个,所以我从中构建了SpecFlow.Core.dll。我正在使用xUnit.net 1.5。

但是,当我在spec项目的app.config中更改unitTestProvider名称时,我得到一个空引用自定义工具错误,生成的.feature.cs文件是单行:

Object reference not set to an instance of an object.

有没有人成功让SpecFlow与xUnit.net合作?如果是这样,怎么样?

3 个答案:

答案 0 :(得分:12)

我遇到了同样的问题并找到了答案。只需使用SpecFlow的lates dist,我使用的是1.3.5.2。 然后,您所要做的就是添加对xUnit.dll的引用,并使用以下配置为您的Specs项目创建一个App.config文件:

<?xml version="1.0" encoding="utf-8" ?>
  <configuration>
    <configSections>
       <section name="specFlow" type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow"/>
    </configSections>

    <specFlow>
       <language feature="en-US" />
         <unitTestProvider name="xUnit" />

         <runtime detectAmbiguousMatches="true" stopAtFirstError="false"
                 missingOrPendingStepsOutcome="Inconclusive" />

         <trace traceSuccessfulSteps="true" traceTimings="false"
             minTracedDuration="0:0:0.1" />
    </specFlow>
  </configuration>

这里的诀窍是 unitTestProvider 元素。

答案 1 :(得分:6)

答案 2 :(得分:3)

在SpecFlow-Example存储库中有一个带有xUnit的SpecFlow示例:

http://github.com/techtalk/SpecFlow-Examples/tree/master/BowlingKata/BowlingKata-XUnit

为了运行它,你必须从github(master分支)上的最新源构建SpecFlow。 您还应该安装SpecFlow 1.2以获得正确的VisualStudio集成。 然后使用从source构建的程序集替换安装目录中的所有程序集(默认Program Files(x86)\ TechTalk \ SpecFlow)。

在此之后,您应该能够构建并运行上面的SpecFlow-Example项目。

希望这有帮助吗?