Specflow: Feature.cs not getting included automatically to test project

Created on 10 Dec 2019  Â·  7Comments  Â·  Source: SpecFlowOSS/SpecFlow

SpecFlow Version:

  • [x] 3.1
  • [ ] 3.0
  • [ ] 2.4
  • [ ] 2.3
  • [ ] 2.2
  • [ ] 2.1
  • [ ] 2.0
  • [ ] 1.9

Used Test Runner

  • [ ] SpecFlow+Runner
  • [ ] MSTest
  • [x] NUnit
  • [ ] Xunit


Version number: NUnit 3.12.0

Project Format of the SpecFlow project

  • [x] Classic project format using packages.config
  • [ ] Classic project format using <PackageReference> tags
  • [ ] Sdk-style project format

.feature.cs files are generated using

  • [x] SpecFlow.Tools.MsBuild.Generation NuGet package
  • [ ] SpecFlowSingleFileGenerator custom tool

Visual Studio Version

  • [x] VS 2019
  • [ ] VS 2017
  • [ ] VS 2015

Enable SpecFlowSingleFileGenerator Custom Tool option in Visual Studio extension settings

  • [ ] Enabled
  • [x] Disabled

Are the latest Visual Studio updates installed?

  • [x] Yes
  • [ ] No, I use Visual Studio version <Major>.<Minor>.<Patch>

.NET Framework:

  • [x] >= .NET 4.5
  • [ ] before .NET 4.5
  • [ ] .NET Core 2.0
  • [ ] .NET Core 2.1
  • [ ] .NET Core 2.2
  • [ ] .NET Core 3.0

Test Execution Method:

  • [x] Visual Studio Test Explorer
  • [ ] TFS/VSTS/Azure DevOps – Task – PLEASE SPECIFY THE NAME OF THE TASK
  • [ ] Command line – PLEASE SPECIFY THE FULL COMMAND LINE

Issue Description


When I create the feature file and build the code, feature.cs is created in the same folder but it doesn't get automatically included in the project. Because of this, the tests are not visible in Test Explorer. Every time I have to manually add the feature.cs file to project. After that the tests are visible in Test Explorer.

Attached below the sample project I created
SpecFlowTest.zip

Bug Generator medium medium

All 7 comments

I have the same issue, only with VS2017 and MSTest.

In the old csproj format (the big xml) the feature.cs files aren't displayed in the solution explorer. This is a limitation in the old project system. It works in the new sdk-style format.
But that doesn't matter, because the files are compiled and the classes are in the compiled assembly. This is all done in the SpecFlow.Tools.MSBuild.Generation package.

The reason you don't see the scenarios in the test explorer is, that you didn't have the NUnit3TestAdapter NuGet package in your project.
I removed the feature.cs files and added the NuGet package and the tests were displayed in the Test Explorer.

In the old csproj format (the big xml) the feature.cs files aren't displayed in the solution explorer. This is a limitation in the old project system. It works in the new sdk-style format.
But that doesn't matter, because the files are compiled and the classes are in the compiled assembly. This is all done in the SpecFlow.Tools.MSBuild.Generation package.

The reason you don't see the scenarios in the test explorer is, that you didn't have the NUnit3TestAdapter NuGet package in your project.
I removed the feature.cs files and added the NuGet package and the tests were displayed in the Test Explorer.

That worked like a charm for me! Thank you so much!
(of course, I used MSTest.TestAdapter in stead)

@Lavernessa Thanks for the feedback. Good too know that it works now for you.
@sanalkr Did it also work for you?

@SabotageAndi It worked. Thank you so much.

Including xxx.feature.cs file into the project is the only way to make F12 / "Go To Test" function work. And without this feature it's almost impossible to use.
I've tried all xUnit, NUnit, MSTest - same problem everywhere

Including xxx.feature.cs file into the project is the only way to make F12 / "Go To Test" function work. And without this feature it's almost impossible to use.
I've tried all xUnit, NUnit, MSTest - same problem everywhere

We've got the same problem (in both VS2017 and VS2019). Using the old .csproj-format, and using MSTest.TestAdapter, the tests _do_ appear in the Solution Explorer, but you can not jump to the the Feature-file from there. The bottom pane of Test Explorer shows "Source: no source available".
image

Should this be posted as a separate issue?

Was this page helpful?
0 / 5 - 0 ratings