Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run SpecFlow tests in Visual Studio 2010?

Trying to get SpecFlow running with a fresh VS2010 Professional install. Created a new console application and added references to NUnit and SpecFlow. Created a SpecFlow feature. The .feature with the default template code is created.

Now I try to run this test, but I don't understand how. When I right-click the project (at the top-level), there is no "Run test(s)" option in the mouse drop down menu. Didn't the SpecFlow install correctly, am I missing some references or some other tool I need to install?

like image 610
testerboy Avatar asked Jun 06 '10 13:06

testerboy


People also ask

How do I debug SpecFlow tests in Visual Studio?

If the execution of a SpecFlow test is stopped at a certain point of the binding (e.g. because of an exception), you can navigate to the current step in the feature file from the “Call Stack” tool window in Visual Studio. By default, you cannot debug inside the generated . feature.


2 Answers

If you want to be able to run your tests directly from Visual Studio 2010 without any additional tools or extensions than you should configure SpecFlow to use MsTest as its unit test framework.

This can be done in your application configuration file with the following:

  <configSections>      <section         name="specFlow"         type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow"/>    </configSections>    <specFlow>      <unitTestProvider name="MsTest" />      <!--         Use this if you're running VS2010         <unitTestProvider name="MsTest.2010" />     -->   </specFlow>  

The generated code-behind file will then contain MsTest tests that are recognisable by Visual Studio and can be run with the build-it test runner.

No need to use NUnit at all.

like image 97
mfloryan Avatar answered Sep 19 '22 13:09

mfloryan


SpecFlow does not provide a runner itself.
SpecFlow generates fixtures for one of the common Unit-Test-Frameworks. In SpecFlow 1.3 NUnit (default), MSTest and xUnit.net are supported (configured in the App.config).

To run the fixtures you have to use a runner that is capable of running them. ReSharper is a very good option for a test runner that is integratied in VisualStudio, but it is not free. ReSharper gives you the "Run Unit Tests" context menu in the solution explorer, you are referring to.

An alternative for VisualStudio integration is TestDriven.Net (also providing a context menu).

For NUnit you can also use the runners that come with NUnit itself (there is a GUI-Runner and a commandline runner).
For MSTest you can use the native VisualStudio integration for running tests (however I find that one a bit clumsy).
xUnit.net also comes with its runners, however I am not familiar with them.

Furthermore, you can use MSBuild tasks to run the fixtures ...

like image 40
jbandi Avatar answered Sep 19 '22 13:09

jbandi