3
votes

I have a VS2010 unit test project set to using SpecFlow 1.8.1 and mstest. In order to get the SpecFlow unit tests working, I've done the following:-

  1. I added the references to the following files in my project:-

    Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll
    TechTalk.SpecFlow.dll

    Note that the TechTalk.SpecFlow.dll has been added into my project and the reference points to that file.

  2. I've set the "Copy Local" property of the TechTalk.SpecFlow.dll reference to True.

  3. I've also added an App.Config that specifies "MsTest.2010" as the provider, and regenerated all code-behinds for the SpecFlow features.

Everything works in my VS2010, the tests run successfully in both the SpecFlow testrunner and the mstest test runner. BUT when I try to run the mstests in TFS 2008 (using a .vsmdi test list file), it failed with the following exception:-

Class Initialization method MyNamespace.MyTestFeature.FeatureSetup threw exception.
System.Configuration.ConfigurationErrorsException:
System.Configuration.ConfigurationErrorsException: An error occurred creating the
configuration section handler for specFlow: Could not load file or assembly
'TechTalk.SpecFlow' or one of its dependencies. The system cannot find the file
specified. (D:\Projects\TestProject\TestResults\administrator_MYPC 2012-06-27
18_30_05_Any CPU_Debug\Out\TestProject.DLL.config line 4) --->
System.IO.FileNotFoundException: Could not load file or assembly 'TechTalk.SpecFlow'
or one of its dependencies. The system cannot find the file specified.

Note that the TFS built the project fine and it runs other unit tests in the same project (normal mstests, not SpecFlow) without problems. It only failed for the SpecFlow test runs.

So what am I doing wrong?

Edit: The contents of my App.Config file looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section
       name="specFlow"
       type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow"/>
  </configSections>
  <specFlow>
    <unitTestProvider name="MsTest.2010" />

    <runtime detectAmbiguousMatches="true"
         stopAtFirstError="false"
         missingOrPendingStepsOutcome="Inconclusive" />

    <trace traceSuccessfulSteps="true"
           traceTimings="false"
           minTracedDuration="0:0:0.1" />
  </specFlow>
</configuration>
5
Can you copy your app.config file too? Mine looks like this: pastebin.com/exKSSdPmt3hn00b
I've added the App.Config file contents as above.SF Lee
Note that I'm using VS2010, so my provider has to be "MsTest.2010", not "MsTest".SF Lee
Maybe that's the cause - I'm using VS2010 too.t3hn00b
Not a clue. The other thing that's different is the platform - you've set it up for Any CPU, mine is x86.t3hn00b

5 Answers

2
votes

Following the instruction on this site and this site:

the command Tools > Library Package Manager > Package Manager Console allows you to type in PM> Install-Package SpecFlow

when the prompts returns "installed successfully", the SpecFlow Assembly now appears in the references of your project. And the MSTest project now compiles succesfully (at least for me).

1
votes

I got this error as well, in my case the problem was that I was using the \...\obj\Debug||Release\ folder as target and not the \...\bin\Debug||Release\ folder. Looking in these folders I saw that the TechTalk.dll assembly was missing from the former. Simply switching in my .bat file the problem was fixed.

1
votes

Sometimes VS2013 is looking for SpecRun dlls not in project folder, but in C:\Users\**YOUR_USER**\AppData\Local\Temp\VisualStudioTestExplorerExtensions\SpecRun.Runner.1.3.0\tools. So you just need to put all necessary SpecFlow libraries therel

0
votes

One hack I found to get it working is to add another class for EVERY single SpecFlow feature that I created in the project. The class looks like this:-

[DeploymentItem(@"TechTalk.SpecFlow.dll")]
partial class MyTestFeature { }

// The above class-name needs to come from the auto-generated code behind
// (.feature.cs) for each SpecFlow feature.

I consider this as a very nasty hack, but it does provide a clue as to why it didn't work. It would be good if anyone comes up with a more elegant solution.

0
votes

I finally found the more proper fix for this issue. I just need to add a post-build event to remove the .config file from the build output. (The App.config file is used only to generate the code-behind during design time. It is not used at all during runtime, so it can be removed.)

The command for the post-build event looks like this:-

del /f /q "$(TargetDir)$(TargetFileName).config"

Correction: The .config file is used for generating inconclusive results, so a better post-build event command is as follows:-

if "$(IsDesktopBuild)"=="false" del /f /q "$(TargetDir)$(TargetFileName).config"