English 中文(简体)
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?

问题回答

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.

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 ...

Just to update this questions, in the latest versions of specflow you should use, (use MsTest.2010)

<configSections> 
    <section 
       name="specFlow" 
       type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow"/> 
  </configSections> 
  <specFlow> 
    <unitTestProvider name="MsTest.2010" /> 
  </specFlow> 

see SpecFlow wrongly using NUnit

I have written a blog post on how to use a batch file as an external tool to automatically run SpecFlow features in NUnit and generate a html report. See: http://watirmelon.com/2011/02/18/c-sharp-atdd-on-a-shoestring/

Something that caught me out. I had to ensure that the Project Type was a Test Project. I had to unload the project and change the Project GUID to that of a Unit Test Project. Once I did that the SpecFlow (and any other) test in the project sprang to life

The Specflow tests are run using the NUnit (GUI), which needs to be invoked externally or alternatively TestDriven.net or Resharper can be installed to support running the tests from inside Visual Studio.

I have created a video demonstrating how to use Specflow with VS2010 here

You can also try Visual Nunit, an open source NUnit test runner plugin to Visual Studio 2008 and 2010. Get it using NuGet, for more info see http://www.bubblecloud.org/visualnunit





相关问题
Best practices for Subversion and Visual Studio projects

I ve recently started working on various C# projects in Visual Studio as part of a plan for a large scale system that will be used to replace our current system that s built from a cobbling-together ...

Enable PHP highlights in VS 2010?

I ve heard that Visual Studio 2010 Beta 2 has support for PHP. When I load a PHP file though, it has nothing highlighted and is nothing more than a glorified text editor. Is there a way to enable it?...

Do I want Publish or Release Build in VB.net?

I wrote a little (like 40 lines little) Winforms application with VB.net in Visual Studio 2010. Now I ve released the code as a Google Code project. It s easy for a developer to get the source but I d ...

Unit Testing .NET 3.5 projects using MStest in VS2010

There s a bug/feature in Visual Studio 2010 where you can t create a unit test project with the 2.0 CLR. https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=483891&wa=...

热门标签