Specflow error: Force regenerate steps possible?

后端 未结 11 1783
猫巷女王i
猫巷女王i 2021-02-01 14:32

Is it possible to \"force\" regenerate step definitions for a specflow feature file? I have created this feature file but cannot generate all steps. Am getting a message that al

相关标签:
11条回答
  • 2021-02-01 15:10
    • Close Visual Studio
    • Open the .csproj in an text editor like NotePad ++
    • Assuming you are using SpecFlow 2.2.0
    • Assuming your features are in ./Features
    • In the <Project> area you should see some <Import> commands, add this:

      <Import Project="..\packages\SpecFlow.2.2.0\tools\TechTalk.SpecFlow.targets" Condition="Exists('..\packages\SpecFlow.2.2.0\tools\TechTalk.SpecFlow.targets')" />
      <!--<ItemGroup>
        -->
      <!-- include all feature files from the folder "FeatureFiles" -->
      <!--
        <None Include="Features\**\*.feature" /> 
      </ItemGroup>
      <Target Name="AfterUpdateFeatureFilesInProject">
          -->
      <!-- include any files that specflow generated into the compilation of the project -->
      <!--
          <ItemGroup>
              <Compile Include="@(SpecFlowGeneratedFiles)" />
          </ItemGroup>
      </Target>-->

    Insert this snippet just inside the <Project></Project> part of you .csproj, next to the other <Import>s if you can. The commented part is important, it will regenerate the .feature.cs files

    • Re-open Visual Studio
    • Everytime you Build the .feature.cs files will be renegerated
    • You may want to add *.feature.cs to your .gitignore after this
    0 讨论(0)
  • 2021-02-01 15:11

    If you are using the SpecFlow plugin in Visual Studio, you can see which lines have bindings as opposed to the ones that don't due to the highlighting. In addition you can also press F12 to go to the items that have Bindings, generate a binding that can be pasted in where it doesn't exist.

    Also I've not seen this process of generating all the steps in one go as you describe above. To be honest it seems a little counter intuitive as SpecFlow already specifically has warning conditions for when the steps don't exist.

    0 讨论(0)
  • 2021-02-01 15:11

    I have encountered the same problem. Restarting Visual Studio will get the job done - SpecFlow is caching the bindings somewhere.

    This looks like a bug to me. It can be reproduced by moving the generated step class. I believe that when you click the "Generate Step Definitions" the engine hits the cache and does not check for the actual file.

    I am testing this on Visual Sudio 2013 with SpecFlow plugin in a plain simple dll project.

    0 讨论(0)
  • 2021-02-01 15:11

    I had a issue which is not updating the designer file of the feature file. I was able to fix that issue by doing the below workaround and now my feature file designers are getting updated. Tools -> SpecFlow -> General -> And Enabled the specflow single file generator.

    Specflow version - 2.2.1 Visual studio 2017 and 2019

    0 讨论(0)
  • 2021-02-01 15:13

    I had to restart VS and it worked for me. Didn't need to delete any temp files or anything else.

    yeah it's a little inconvenient but the lesser of all evils I think.

    0 讨论(0)
  • 2021-02-01 15:15

    SpecFlow creates a .cache file in your Temp folder that holds these bindings to speed things up. If that file gets out of whack, you can delete it:

    1. Exit Visual Studio.
    2. Open Windows Explorer.
    3. In the address bar, type %TEMP% and hit Enter to go to your temp folder.
    4. Find the files whose names start with "specflow-stepmap-YourProjectName" with a .cache extension.
    5. Delete those files.
    6. Start Visual Studio again.

    If you do this, it'll take a little time for SpecFlow to regenerate the bindings. Until this is done, if you right-click on a step and select "Go To Step Definition", Visual Studio will reply "Step bindings are still being analyzed. Please wait."

    I most commonly use this for the opposite case, where SpecFlow shows that nothing is bound even though the steps exist. But I think it's likely to work for your case as well.

    0 讨论(0)
提交回复
热议问题