简体   繁体   中英

Specflow features aren't auto-generating cs files or appearing as tests in C# Nunit project

(updated this post for clarity)

I am unable to create a starting point C# Specflow Nunit project (contrary to following online tutorials and videos) whereby new specflow features autogenerate cs files and appear as runnable tests.

Steps to reproduce:

  1. Install Visual Studio Community 2019 v16.3.5

  2. Extensions > Manage Extensions: Install Specflow for VS 2019 (v2019.0.36.11860). Restart VS to accept Specflow installation on wizard.

  3. New Project > Test > C# Unit Test Project (.Net Framework, C#, Windows, Test). Name: myProject Framework: 4.7.2

  4. Delete UnitTest1.cs auto generated project file

  5. From NuGet Manager for solution, add package: Specflow.NUnit v3.0.225 (select OK to make changes to solution, and accept package licences

  6. Add two folders to the project: Features, StepBindings

  7. An new item to Features folder: Specflow Feature File (type: Visual C# Item) name myFeature.feature

outcome: no autogenerated feature cs file appears under the new green myFeature.feature file

solution warning: Cannot find custom tool 'SpecFlowSingleFileGenerator' on this system. (File: myFeature.feature)

Note: Enable SpecFlowSingleFileGenerator is set to False under Tools > Options > Specflow

  1. Right click on a step within myFeature.feature > generate step definitions > save as 'myFeatureSteps.cs' in StepBindings folder outcome: solution warnings: ScenarioContext.Current is obsolete (File: myFeature.feature lines 12, 18, 24)

  2. View-Test Explorer

outcome: No tests shown, including when clicking run all (to trigger a build / discover tests / run in solution)

Further exploratory steps:

  1. (required?) Added nuGet package: NUnit3TestAdapter v3.15.1

  2. Updated nuGet package NUnit to v3.12.0

  3. Rebuilt project, clicked runAll in testexplorer, restarted Visual Studio

final outcome: still no tests showing in runner, and auto generated code still shows with errors (ScenarioContext.Current)

packages.config:

<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="BoDi" version="1.4.1" targetFramework="net472" />
<package id="Gherkin" version="6.0.0" targetFramework="net472" />
<package id="MSTest.TestAdapter" version="1.3.2" targetFramework="net472" />
<package id="MSTest.TestFramework" version="1.3.2" targetFramework="net472" />
<package id="NUnit" version="3.12.0" targetFramework="net472" />
<package id="NUnit3TestAdapter" version="3.15.1" targetFramework="net472" />
<package id="SpecFlow" version="3.0.225" targetFramework="net472" />
<package id="SpecFlow.NUnit" version="3.0.225" targetFramework="net472" />
<package id="System.Reflection.Emit" version="4.3.0" targetFramework="net472" />
<package id="System.Reflection.Emit.Lightweight" version="4.3.0" targetFramework="net472" />
<package id="System.Threading.Tasks.Extensions" version="4.4.0" targetFramework="net472" />
<package id="System.ValueTuple" version="4.4.0" targetFramework="net472" />
<package id="Utf8Json" version="1.3.7" targetFramework="net472" />
</packages>

Note: the top packages element is underlined as "not declared"?

Code to try and get project working: https://github.com/bobjames238745/getSpecflowWorkingWithNunit

After looking at your NuGet packages, you need to install the SpecFlow.Tools.MsBuild.Generation package before the feature.cs files will be created on-build.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM