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

Mik*_*ott 5 xunit.net specflow

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

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

Object reference not set to an instance of an object.
Run Code Online (Sandbox Code Playgroud)

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

Gar*_*mel 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>
Run Code Online (Sandbox Code Playgroud)

这里诀窍的部分是unitTestProvider元素.


jba*_*ndi 5

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

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

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

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

希望这可以帮助?