【问题标题】:SpecFlow not listing NUnit in Tools->Options->SpecFlow->TestRunnerToolSpecFlow 未在 Tools->Options->SpecFlow->TestRunnerTool 中列出 NUnit
【发布时间】:2012-03-27 15:19:25
【问题描述】:

在 Visual Studio 2010 Pro 上,我在同一个类库中有来自 NuGet 的 SpecFlow 和 NUnit(分别)。 App.Config 是:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="specFlow" type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow" />
  </configSections>
  <specFlow>
    <!-- For additional details on SpecFlow configuration options see https://github.com/techtalk/SpecFlow/wiki/Configuration -->
    <unitTestProvider name="NUnit" />
  </specFlow>
</configuration>

我有正确使用 NUnit 的默认模板功能文件,如下所示:

        [NUnit.Framework.TestAttribute()]
        [NUnit.Framework.DescriptionAttribute("Add two numbers")]
        [NUnit.Framework.CategoryAttribute("mytag")]
        public virtual void AddTwoNumbers()
        {
            TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Add two numbers", new string[] {
                        "mytag"});
#line 7
this.ScenarioSetup(scenarioInfo);
#line 8
 testRunner.Given("I have entered 50 into the calculator");
#line 9
 testRunner.And("I have entered 70 into the calculator");
#line 10
 testRunner.When("I press add");
#line 11
 testRunner.Then("the result should be 120 on the screen");
#line hidden
            this.ScenarioCleanup();
        }

Tools->Options->SpecFlow->TestRunnerTool 设置为 auto,但我看到 NUnit 没有在下拉列表中列出。

当我右键单击功能文件并尝试运行场景(关于计算器的默认场景和模板中的两个数字)时,弹出对话框显示“找不到匹配的测试运行器。请在'中指定测试运行器工具”工具/选项/SpecFlow'

如何在该下拉菜单中获取 NUnit?或者我还能做些什么来让 SpecFlow 运行功能文件?

NUnit.Framework.dll 运行时版本 v 2.0.50727 NUnit.Framework.dll 版本 2.6.0.12051

TechTalk.SpecFlow.dll 运行时版本 2.0.50727 TechTalk.SpecFlow.dll 版本 1.8.1.0

【问题讨论】:

  • 所以项目(两个 dll)构建。我没有在 Visual Studio 中使用右键单击运行场景,而是打开了 NUnit 并从那里运行测试。这行得通。

标签: testing nunit config specflow


【解决方案1】:

SpecFlow.org 网站 (http://www.specflow.org/specflownew/ProjectSetupGuide.html) 上的示例使用 SpecRun (http://nuget.org/packages/SpecRun.NUnit)。 SpecRun 是将 NUnit 与 Visual Studio 集成的一种方法,因此您可以通过右键单击执行 SpecFlow/NUnit 测试。 SpecRun 不是免费工具。您不会在该工具/选项/SpecFlow 下拉列表中看到 NUnit,但如果您已通过 NuGet 安装该工具,您将看到 SpecRun。

如果您有 ReSharper,也支持通过右键单击运行 SpecFlow 测试。

http://www.youtube.com/watch?v=c2ge90BWeI0

【讨论】:

    【解决方案2】:

    在学习 BDD 的过程中,我偶然发现了这篇博文,它对我非常有用,它解释了从设置到使用 SpecFlow/NUnit 运行测试的各个方面。

    Behaviour Driven Development (BDD) in .Net using SpecFlow, Selenium and NUnit

    至于 SpecFlow 二进制文件,它们并不容易找到。由于我更喜欢​​这种方式,因此我在 SpecFlow 网站上进行了一些更深入的挖掘,以找到提供二进制文件的页面:Advanced Project Setup

    【讨论】:

      猜你喜欢
      • 2014-10-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-11
      相关资源
      最近更新 更多