NUnit not specified as test runner for SpecFlow - visual-studio-2010

For the life of me I cannot get SpecFlow configured to use NUnit as the test runner. NUnit is not listed in the Tools > Options > SpecFlow test runner dropdown, and the "auto" setting doesn't find NUnit.
I've tried reinstalling both NUnit and SpecFlow multiple times. Tried installing SpecFlow 1.8.1 and 1.9 to no avail. Tried using app.config. I've even tried re-installing Visual Studio 2010.
I just want SpecFlow to use NUnit (2.6.1). Can anyone help?

Visual Studio->Tools->Extensions and updates->Online->search "Test Adapter"->install.
http://visualstudiogallery.msdn.microsoft.com/6ab922d0-21c0-4f06-ab5f-4ecd1fe7175d
better late than never.

Try editing the config file of your unit test project:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="specFlow" type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow" />
</configSections>
<specFlow>
<unitTestProvider name="NUnit" />
</specFlow>
</configuration>
Check out the config documentation here.

SpecFlow itself does not provide a test runner and if you want to right click on the .feature and run it, you'll have to re-configure SpecFlow to use MSTest, which should use built-in VS runner.
If you want to use NUnit, then additional tools are required. I would recommend Resharper, but it's not free. This article should help you choose a way to run NUnit tests from VS.
Good luck

To get integration with Visual Studio, you need to install the SpecFlow Extension. SpecFlow comes in 2 parts.
The NuGet package contains the dlls necessary to author and run the tests.
The Visual Studio Extension which gives you Intellisense, syntax highlighting, code navigation, and the ability to run tests by right clicking and choosing "Run SpecFlow Scenarios".
I am guessing you have installed the Nuget package, but haven't installed the extension.
To install the extension:
Open Visual Studio
Choose Tools -> Extension Manager
Search for the SpecFlow extension
Click install

Related

Go To Test (F12) doesn't work in Test Explorer in Visual Studio

When I click on Go To Test or use F12, nothing happens. This happens for SpecFlow tests in VS2019. This is an issue because it is difficult to manually find the test in the *.feature file.
Is there any way for me to make it start working again?
P.S. I found a similar issue described in https://github.com/SpecFlowOSS/SpecFlow/issues/1457
Edit: I am using VS2019 16.8.5, .NET Framework 4.8, my csproj uses the old XML format, and I am using a SpecFlow feature where *.feature.cs are not under source control.
<Import Project="..\packages\SpecFlow.Tools.MsBuild.Generation.3.0.225\build\SpecFlow.Tools.MsBuild.Generation.targets" Condition="Exists('..\packages\SpecFlow.Tools.MsBuild.Generation.3.0.225\build\SpecFlow.Tools.MsBuild.Generation.targets')" />
<Import Project="..\packages\SpecFlow.NUnit.3.0.225\build\SpecFlow.NUnit.targets" Condition="Exists('..\packages\SpecFlow.NUnit.3.0.225\build\SpecFlow.NUnit.targets')" />
As you already found out, this is a known issue with the old project format.
There are two possible workarounds for you:
convert to the new sdk format for csproj
Use the SpecFlow+ Runner as unit test runner

How to Configure Specflow 3.0.199 with NUnit 3.11?

I have done this a couple of times before, but it's not working today. Am I missing something?
I want to configure Specflow from the scract, using NUnit and to execute inside Visual Studio.
I've seen many tutorials but they are not working to me :P. I'm trying to use the latest versions.
These are the steps I'm doing on Visual Studio 2017:
Create a test project (.NET Framework)
Install Specflow plugin for Visual Studio (Tools > Extensions and Updates)
Delete reference of MSTests from the nuget packages.
Install SpecFlow 3.0.199
Install NUnit 3.11
Install SpecRun.Runner 3.0.284
After creating a default feature file and generate its steps, when I compile the solution I get this error on CalculatorFeature.feature.cs (the generated file):
It's like those configurations are not compatible. What's going on?
If you have another step by step list, let me know how to configure Specflow with NUnit to run on Visual Studio 2017, please.
For SpecFlow 3 you have to use the MSBuild generation.
To this, follow these two steps:
Add the NuGet package SpecFlow.Tools.MsBuild.Generation with the same version as SpecFlow to your project
Remove all SpecFlowSingleFileGenerator custom tool entries from your feature files.
From https://specflow.org/2019/generating-code-behind-files-using-msbuild/
Background what is happening:
The VS Extension has sometimes problems to find the used SpecFlow version. In that case, it falls back to the SpecFlow version shipped with the extension (which is really old). This version is generating code with now not existing NUnit attributes.
TestFixtureSetUp and TestFixtureTearDown attributes were deprecated for quite some time and were finally removed. They are replaced by OneTimeSetUp and OneTimeTearDown.
Your choices are probably...
Go back to an NUnit version that supports the old attributes.
Get a version of SpecFlow that uses the new attributes.
Find a way to configure SpecFlow and tell it to use the new attributes. Sorry, but this option, which is no doubt the best, is out of my wheelhouse.

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

Gallio test runner plugin to Visual Studio 2008 and 2010 for MBUnit tests

If I install Gallio 3.x will it also install a test runner plugin for Visual Studio?
Or must I use an additional plug-in like TestDriven.NET or Visual Nunit to run MbUnit test classes from within VS?
Install Gallio 3.1 on the dev machine. Then in VS2008, you'll have the option to create a "MbUnit v3 Test Project". This doesn't just include all of the Gallio dlls for you, it has a magic line in the project which identifies it to VS as a Test project.
You can now just use the in-built VS2008 Test runner.
If you have any existing projects with unit tests in, rather than making new projets, edit your existing project file and add the following line on line 9 (underneath the <ProjectGuid> on line 8):
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
(If you have a VB project, it has a different second GUID: <ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{F184B08F-C81C-45F6-A57F-5ABD9991F28F}</ProjectTypeGuids> You can find the correct values by creating a new MbUnit test project from the templates installed with Gallio and then looking at the project file (.csproj or .vbproj) in a text editor.)
Now when you reload the project, VS2008 will recognise it as a test project.
A distinct advantage that I found over using Icarus was that debugging is now far more straight forward with break points being hit as expected.
Good Luck, Lee
TestDriven.Net works really well. Gallio also supports the ReSharper unit test runner and Visual Studio test tools. We will be shipping a new release of Gallio this week with support for R# 5.0 and VS 2010.
These are instruction for running MBUnit tests in Visual Studio 2012 and above using a neat NUnit trick.
Firstly, install the NUnit Test Adapter extension (yes, NUnit)
Tools > Extension and Updates > Online > search for NUnit > install
NUnit Test Adapter.
You may need to restart the Visual Studio IDE.
Then, you simply need to add a new NUnit test attribute to your test methods. See example code here (notice the using statements at the top) ...
//C# example
using MbUnit.Framework;
using NuTest = NUnit.Framework.TestAttribute;
namespace MyTests
{
[TestFixture]
public class UnitTest1
{
[Test, NuTest]
public void myTest()
{
//this will pass
}
}
}
You can run and debug the test in visual studio as NUnit and Gallio Icarus GUI Test Runner will run them as MBUnit (enabling parallel runs for example). You will need to stop Gallio from running the NUnit tests by deleting the NUnit folder in the gallio install location i.e. C:\Program Files\Gallio\bin\NUnit
Hope this helps, this is a simple working method so please vote up, many thanks.

NUnit isn't running Visual Studio 2010 code

I'm trying to load a Visual Studio 2010 beta dll into the NUnit GUI. I get a popup error.
This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded. You may be attempting to load an assembly build with a later version of the CLR than the version under which NUnit is currently running.
How do I force an executable to run under .NET 4?
I've downloaded the NUnit 2.5 source and opened the VS2008 solution in the VS2010 beta. Once the conversion finished I opened all the projects and changed the target framework setting for all the projects to ".NET Framework 4.0". I then built the solution without any errors. I can now use the NUnit GUI app to run tests built for .NET 4.0. I've not done exhaustive testing of this build so there may be problems, but for my purposes it works fine.
Update: It is not necessary to rebuild NUnit. I discovered that if you add the following to the relevant NUnit config file you can run a test dll built for .NET 4.0.
Under <configuration> add:
<startup>
<supportedRuntime version="v4.0.30319" />
</startup>
and under <runtime> add:
<loadFromRemoteSources enabled="true" />
With .NET 4 being released, I used
<supportedRuntime version="v4.0.30319" />
in the NUnit 2.5.4 exe.config instead of requiredRuntime, and the loadFromRemoteResources tag as shown above and all worked well. Thanks!
You don't have to modify any file
just open this file and everything will work just fine
C:\Program Files (x86)\NUnit 2.5.10\bin\net-2.0\nunit-x86.exe
In NUnit 2.5.5 you can specify in the command line the option /framework=net-4.0 and it is compatible with the new assemblies generated with the release of the latest VS2010.
The proposed solution worked great for getting NUnit to run. Unfortunately, when I then got to my code coverage step, NCover started giving me:
Profiled process terminated. Profiler
connection not established.
The best solution I found to this was to just use the "-x86" version of NUnit with NCover:
NCover.Console.exe
nunit-console-x86.exe --additional params--
Works now.
To find your .net 4 version from the Visual [C# 2010 Express, or which ever] go to the Visual application's "About" under the menu's Help item. It should show up as the version under the Microsoft .NET Framework line on the top right hand side of the window.
I ran into the very same error message while running NUnit 2.4.8. As I had not upgraded in some time I installed the current NUnit (v2.5.9) and found that it now supports VS2010 assemblies. So if you have newly encountered this error check your NUnit version: as of December 2010 (or so) the only thing you need to do is upgrade NUnit.
As of NUnit 2.5.10 you can enable visual studio support in the GUI runner:
Tools-> Settings-> IDE Support
After that I was able to successfully attach to the nunit-agent.exe process which runs your assembly in a .NET 4.0 app domain
If you experience this issue after upgrading to nunit 2.5.5 then you will need to upgrade nant to the latest version for me it was .91 alpha.
I found usefull to start from NUnit Application Template. It support VS C# Express, allows debugging tests and contains precompiled NUnit for .NET 4.0. Thank to author new test project gets ready with one click.

Resources