6

I have gone through the Getting Started tutorial for SpecFlow. Everything worked fine except that I have the @SpecRun test because I have not entered a demo key.

But in our main project we use NUnit instead of SpecFlow+ Runner. So I tried to mimic that project. If you use NUnit you won't need the demo key. So I changed the Unit Test Provider to:

<specFlow>
  <unitTestProvider name="NUnit" />
</specFlow>

I also compared my tutorial references to the main project's references. I find that I can take out TechTalk.SpecRun and the project will still compile. Of course TechTalk.SpecFlow is needed.

If I take out SpecRun.SpecFlowPlugin, no tests show up except @SpecRun which is the tests delay without the demo key.

I also see in the main project a csharp file called: SpecFlowNUnitExtension.cs. I brought in this file but my tests still do not show up in the Visual Studio Test window. Is there something I need to do to register this file?

Sam
  • 4,766
  • 11
  • 50
  • 76
  • Related post - [Built tests are not added to the Visual Studio Test Explorer window](https://stackoverflow.com/q/30573482/465053) – RBT Feb 17 '21 at 05:21

5 Answers5

11

You need a test runner adapter for Visual Studio to get the tests in the test explorer. They are distributed by NuGet packages. Add the package for your test runner to your test project.

  • SpecFlow+Runner: SpecRun.Runner
  • NUnit2: NUnitTestAdapter
  • NUnit3: NUnit3TestAdapter
  • XUnit: xunit.runner.visualstudio
  • MsTest: no additional adapter needed
Gaspar Nagy
  • 4,422
  • 30
  • 42
Andreas Willich
  • 5,665
  • 3
  • 15
  • 22
4

Update your NUnit Test Adapter to NUnit3 Test Adapter. Restart Visual Studio and rebuild the tests should show up.

codester
  • 63
  • 1
  • 7
1

For VS 2019 I spent hours to see runnable tests on test explorer. I am using SpecFlow.xUnit nuget it installs SpecFlow as a dependency and I installed xunit.runner.visualstudio as test runner. Also SpecFlow.Tools.MsBuild.Generation nuget should be installed as mentioned on SpecFlow's getting started page. After seperating feature and generated cs file into different folders in test project I started to run tests on spec. In addition you can see .feature.cs file if you click show all files on your solution explorer.

Murat Seker
  • 890
  • 2
  • 14
  • 26
  • 1
    Thanks for this Murat. I am using VS 2019 Preview 3.1. I installed `SpecFlow.xUnit` NuGet package but that did **not** install the SpecFlow dependency for some reason so I had to install that manually. Also, I had to install the `SpecFlow.Tools.MsBuild.Generation` like you said. After that it was all good! – swatsonpicken Jun 29 '20 at 17:28
0

If you want to your tests - the unit tests generated by Specflow, just for being precise - displayed in your unit test explorer you must create Unit test project. If you created a class library project then you won't see them.

Here you can find information about how you can convert your class library project to unit test project.

Community
  • 1
  • 1
AndrasCsanyi
  • 3,943
  • 8
  • 45
  • 77
  • Yes - it is a Unit Test Project. – Sam Aug 15 '16 at 14:12
  • 2
    Using the Unit Test project template only helps if you use MsTest as Testing Framework, because this template has already the references to it. If you use something other, it does not help. – Andreas Willich Aug 17 '16 at 07:16
0

I was also having same issue in Visual Studio 2019, and I managed to fix by adding following nuget packages:- SpecFlow, SpecFlow.Tools.MsBuild.Generation, SpecRun.SpecFlow