Specflow和Nunit框架入门问题

时间:2019-04-21 12:35:09

标签: nunit specflow

我正在尝试将Specflow + VS2017 + Nunit安装为运行程序。

我执行的步骤:

  1. 安装VS 2017社区版
  2. 安装SpecFlow扩展V.2019.0.9.46639
  3. 设置一个类库(.NET Framework)项目,框架:.NET Framework 461
  4. 安装以下NuGet软件包:

<packages>
  <package id="BoDi" version="1.4.1" targetFramework="net461" />
  <package id="Dapper" version="1.60.6" targetFramework="net461" />
  <package id="Gherkin" version="6.0.0" targetFramework="net461" />
  <package id="NUnit" version="3.11.0" targetFramework="net461" />
  <package id="NUnit.Console" version="3.10.0" targetFramework="net461" />
  <package id="NUnit.ConsoleRunner" version="3.10.0" targetFramework="net461" />
  <package id="NUnit.Extension.NUnitProjectLoader" version="3.6.0" targetFramework="net461" />
  <package id="NUnit.Extension.NUnitV2Driver" version="3.7.0" targetFramework="net461" />
  <package id="NUnit.Extension.NUnitV2ResultWriter" version="3.6.0" targetFramework="net461" />
  <package id="NUnit.Extension.TeamCityEventListener" version="1.0.6" targetFramework="net461" />
  <package id="NUnit.Extension.VSProjectLoader" version="3.8.0" targetFramework="net461" />
  <package id="NUnit.Runners" version="3.10.0" targetFramework="net461" />
  <package id="NUnit3TestAdapter" version="3.10.0" targetFramework="net461" />
  <package id="SpecFlow" version="3.0.199" targetFramework="net461" />
  <package id="SpecFlow.NUnit" version="3.0.199" targetFramework="net461" />
  <package id="SpecFlow.NUnit.Runners" version="3.0.199" targetFramework="net461" />
  <package id="SpecFlow.Tools.MsBuild.Generation" version="3.0.199" targetFramework="net461" />
  <package id="System.Reflection.Emit" version="4.6.0-preview4.19212.13" targetFramework="net461" />
  <package id="System.Reflection.Emit.Lightweight" version="4.6.0-preview4.19212.13" targetFramework="net461" />
  <package id="System.Runtime.CompilerServices.Unsafe" version="4.6.0-preview.18571.3" targetFramework="net461" />
  <package id="System.Threading.Tasks.Extensions" version="4.6.0-preview.18571.3" targetFramework="net461" />
  <package id="System.ValueTuple" version="4.5.0" targetFramework="net461" />
  <package id="Utf8Json" version="1.3.7" targetFramework="net461" />
</packages>

一切顺利,直到我必须创建功能文件并运行测试。如果删除自定义工具(https://specflow.org/documentation/Generate-Tests-from-MsBuild/),我将无法再在“测试资源管理器”中查看测试。

[4/21/2019 3:20:49 PM Informational] ------ Run test started ------
[4/21/2019 3:20:51 PM Informational] NUnit Adapter 3.10.0.21: Test execution started
[4/21/2019 3:20:51 PM Informational] Running all tests in source\repos\ClassLibrary1\ClassLibrary1\bin\x86\Debug\ClassLibrary1.dll
[4/21/2019 3:20:51 PM Informational] NUnit couldn't find any tests in source\repos\ClassLibrary1\ClassLibrary1\bin\x86\Debug\ClassLibrary1.dll
[4/21/2019 3:20:51 PM Informational] NUnit Adapter 3.10.0.21: Test execution complete
[4/21/2019 3:20:51 PM Warning] No test is available in source\repos\ClassLibrary1\ClassLibrary1\bin\x86\Debug\ClassLibrary1.dll. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.
[4/21/2019 3:20:52 PM Informational] ========== Run test finished: 0 run (0:00:02.4530052) ==========

这让我在过去的一周里发疯了。我不明白为什么Specflow的家伙没有为所有必需的软件包/库制作简便的安装程序。现在回到问题所在:

如果我转到生成的Step文件并添加例如[测试]属性为:

using System;
using TechTalk.SpecFlow;

namespace ClassLibrary1
{
    [Binding]
    public class SpecFlowFeature2Steps
    {   **[Test]**
        [Given(@"I have entered (.*) into the calculator")]
        public void GivenIHaveEnteredIntoTheCalculator(int p0)
        {
            ScenarioContext.Current.Pending();
        }

        [When(@"I press add")]
        public void WhenIPressAdd()
        {
            ScenarioContext.Current.Pending();
        }

        [Then(@"the result should be (.*) on the screen")]
        public void ThenTheResultShouldBeOnTheScreen(int p0)
        {
            ScenarioContext.Current.Pending();
        }
    }
}

该方案出现在测试浏览器中。

我尝试过: -将CPU架构与测试相匹配

Specflow不能使用Gherkins代码处理NUnit框架属性吗?我究竟做错了什么?谢谢

0 个答案:

没有答案