Why do my SpecFlow tests not show up in Visual Stu

2020-03-19 02:19发布

问题:

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?

回答1:

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


回答2:

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



回答3:

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.