How to get VS2010 to recognize my mstests generated by SpecFlow? - visual-studio-2010

I have configured Specflow to target the MsTest framework (instead of NUnit) by specifying it like this in the app.config of my 'specs' class library:
<configSections>
<section name="specFlow"
type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow"/>
</configSections>
<specFlow>
<unitTestProvider name="MsTest.2010" />
</specFlow>
So once it's in place, I can see that my test fixtures are produced correctly by the Specflow custom tool, with correct TestClassAttribute() and methods, etc:
[System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "1.3.3.0")]
[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute()]
...
The specs class builds, but now I cannot run the tests using the Test --> Run --> All Tests in Solution inside Visual Studio 2010 on my vista 64 box. Why doesn't VS recognize these as valid tests to run?

As per Dror Helper and Alex Duggleby you'll want to add the following line to your .csproj file:
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
Add it after the FileAlignment element, and reload the project. It should now be an MS Test project and you get the MS Test functionality in the context of this project. The Guids mean:
{3AC096D0-A1C2-E12C-1390-A8335801FDAB} - Test Project
{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - C# Class Library

I had to recreate the project as a Test Project and not merely a Class Library -- because I had started development with NUnit and SpecFlow, I had created a vanilla class library to hold my specs that had the NUnit attributes decorated. I thought I could simply change the app.config of this existing project to point at the mstest framework and stop using NUnit, but VS2010 never recognized the tests, despite the correct creation of the stubs by specflow's custom tool.
So...I added a new Test Project to my solution, moved all of my spec code to that new project, then recompiled, and viola, VS2010 recognizes the tests. I'm sure there is a GUID it is looking for in the XML of the .csproj file or something that tells it to wire up the testing framework, but I didn't dig that far.
Hope this helps someone.

To change your class library project template into a test project, modify the .csproj and add the following line:
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
to the first property group element:
<PropertyGroup>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>

Related

Whats the difference between installing a package via NuGet packages and the 'extentions and updates' option from the 'Tools' menu in vs2015?

I have created a project using specflow, so I have a new feature file saved as a class library project, when I try and run the project I get the error: 'A project with an Output Type of Class Library cannot be started directly. In order to debug this project, add an executable project to this solution which references the library project. Set the executable project as the startup project'
I think it's an error with the way I have added the n-unit and specflow references to the project. I have noticed I could install specflow via NuGet packages or extensions and updates. So what the difference between adding packages in these two ways?
They are two different things.
the Specflow extension extends the visual studio ide to support specflow. Specifically:
it adds syntax highlighting support for gherkin syntax
it allows the tests to be generated from .feature files
it adds the file templates to the file types so you can add new feature files/step bindings
it adds the additional context menu options to allow steps to be generated and the navigation between steps in the feature file and steps in the code.
it allows integration with the visual studio unit test windows
and probably a few more things that I've neglected to mention. Without this writing specflow tests in visual studio would be more difficult and the generation of the unit test cases themselves would be not be done.
the nuget package allows an individual project to use specflow. This adds the necessary references to the project so that you can consume the types which specflow uses. without these being referenced the projects which try and use specflow would not compile.
As for your issue, this is not related to specflow in any way. A project which builds a dll cannot be started, it needs something to be hosted in in order to be used any project which is a library will give this error if you set it as the startup project regardless of if you use specflow or not.

MSTest Not Finding New Tests because of missing ProjectTypeGuids in .csproj - Why?

It happened in VS2010 that when creating project, .csproj file didn't generate some tag ProjectTypeGuids in the first PropertyGroup.
This had consequence that I couldn't see in TestView window any MS unit test in that project, nor execute it.
I copied ProjectTypeGuids from some other .csproj file where tests worked, and it worked, by explanation of MoCapitan in:
MSTest Not Finding New Tests
Does anyone knows what is ProjectTypeGuids, why UnitTests are not working without it and what is the reason for VS to generate or to omit it?
ProjectTypeGuids is list of "guid that identifies project type". So if you are missing "this is Unit test project" guid than default VS infrastructure will not try to look for tests in that project (other test runners like R# may still run such tests).
If you created project as regular "class library" (instead of "Unit tests project") than the guids will be missing.
Partial list of types: http://www.codeproject.com/Reference/720512/List-of-Visual-Studio-Project-Type-GUIDs

file not found exception running specflow test with codedui in visualstudio 2013

I've been searching all morning for an answer online to this and I have tried a lot of the suggestions though all solutions seem to be for visual studio 2010 and I am running 2013 premium edition, I can't see anyone with the same problem.
I have premium VS 2013, I installed SpecFlow v1.9 through the extension manager and added the SpecFlow nuget package. I have created a CodedUI test project and added a feature file, some recorded codedui steps and a stepdef file. Nothing is complaining and it all looks like it should work. I have added :
<unitTestProvider name="MsTest"/>
to my App.config so I can run it from the test explorer in visual studio. I eventually want to run the tests via MTM but I will deal with that when I get this to work!
I have built and it is all happy so I go to test explorer and I can see my test so I right click, run the test. It fails with the following error, it does get to my Given step when I debug and falls over trying to open my application.
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.VisualStudio.TestTools.UITest.WindowsStoreUtility, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
I can not find the reference above when I have looked to add it to my project references, there is a similar one but it breaks some of my other references when I add it. I also had a look at my registry files and the path it is referring to does not exist for me to edit it. From what I have read codedui doesn't work nicely with specflow without a dll file. All references to this fix seem to be for vs 2010 and require that I copy a dll to my specflow source folder. I installed specflow from visual studio so I don't have a program files folder for it so I came to a bit of a sticking point with that solution.
Does anyone have specflow working with visual studio 2013 and a codedui test project? Am I missing a set up step? Or is this genuinely to do with my registry files / references. The error is confusing as I don't see why it is trying to find that reference especially when I can't find that reference anywhere when I try to find it manually. I'd be interested to know if you have had this error and managed to resolve it or if you could explain your set up steps so I can check I did not miss anything.
Thanks!
I believe you might be missing references to some of the required dlls. I just finished testing a test created using a Specflow, codedUI test project on my MS Visual Studio 2013 ultimate and it worked just fine.
Here are the steps which I followed:
Created a class library project.
Added reference to Specflow 1.9 from Extensions and Updates.
Added reference to Specflow CodedUI Attribute Generator (Install-Package SpecFlow.CodedUI -Version 1.0.0.23).
Added references to required libraries required for CodedUI and Test Tools to the project. See below the references I added.
Microsoft.VisualStudio.QualityTools.CodedUITestFramework
Microsoft.VisualStudio.QualityTools.UnitTestFramework
Microsoft.VisualStudio.TestTools.UITest.Common
Microsoft.VisualStudio.TestTools.UITest.Extension
Microsoft.VisualStudio.TestTools.UITest.ExtensionUtilities
Microsoft.VisualStudio.TestTools.UITesting
Added a separate CodedUI project to solution and added references of this project to the class library project.
Create a new Specflow feature file with some test and create step for it in step definition and reference to the function you created or recorded in the CodedUI project in the step definition.
Run the Specflow test from Test Explorer. It should work fine.
Note: The above steps should work just fine if you will create CodedUI project instead of a Class library project.
Mark the test class with the CodedUITest attribute.
I had this exact error message even though I had all the .dll's referenced correctly.
The solution for me was to regenerate the feature files.
(right click project and select "regenerate feature files")
Leaving this answer in case it helps someone in future.
I came across the same issue today, not with specflow but 2013 build controller and agent and codedui tests.
The solution was to install VS2013 Update 5 https://www.visualstudio.com/downloads/download-visual-studio-vs
I had same problem, found the following solution works well:
http://blog.majcica.com/2015/05/07/getting-started-with-specflow-and-codedui/

assemblybinding does not work in mstest

I have a very simple MSTest unit test project that indirectly have dependency on two versions of MVC.
assemblybinding in app.config is configured to redirect to MVC v4
when I run mstest test runner (VS2012 RC built-in) - I get exception indicating that assembly binding did not work.
If I create testsettings file and disable deployment (or enable deployment and add app.config to the list of items to deploy) - test passes.
Question: why does assemblybinding works with deployment set to false? Can I make this test pass without using testsettings file?
I am experiencing the same thing with vs2012, mstest and R#, seems to be a confirmed bug according to this:
http://social.msdn.microsoft.com/Forums/en-US/vsunittest/thread/234926d1-42c0-4ebb-af39-1626e72f6c39
Adding link to the same bug report in R#:
http://youtrack.jetbrains.com/issue/RSRP-329567

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

Resources