Amir
Amir

Reputation: 53

specflow behind code has syntax error or duplicate code

I have a solution that consists of a couple of projects. I have 3 categories of projects in my solution. First category only includes the .feature files. The second category only includes the bindings. The third includes the drivers which include a set of functions used in the bindings to communicate with a software interface which I am testing.

When I build my solution, some of the code behind files (.feature.cs) become corrupted. Here are screenshots of what I get after I build the solution:

Build errors in Visual Studio

Build errors in Visual Studio

Below is an example of a corrupted .feature.cs file:

    // ------------------------------------------------------------------------------
//  <auto-generated>
//      This code was generated by SpecFlow (http://www.specflow.org/).
//      SpecFlow Version:2.3.0.0
//      SpecFlow Generator Version:2.3.0.0
// 
//      Changes to this file may cause incorrect behavior and will be lost if
//      the code is regenerated.
//  </auto-generated>
// ------------------------------------------------------------------------------
#region Designer generated code
#pragma warning disable
namespace AcceptanceTests.Controllers.Images
{
    using TechTalk.SpecFlow;


    [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "2.3.0.0")]
    [System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
    [Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute()]
    public partial class GetImagesFeature
    {

        private static TechTalk.SpecFlow.ITestRunner testRunner;

        pr// ------------------------------------------------------------------------------
//  <auto-generated>
//      This code was generated by SpecFlow (http://www.specflow.org/).
//      SpecFlow Version:2.3.0.0
//      SpecFlow Generator Version:2.3.0.0
// 
//      Changes to this file may cause incorrect behavior and will be lost if
//      the code is regenerated.
//  </auto-generated>
// ------------------------------------------------------------------------------
+ Designer generated code

Notice how there are duplicate blocks of code here. It seems like the regenerated code was added somewhere in the middle of the older code (where we see "pr// --- ").

Another example would be a behind code file with syntax error like missing brackets or improper formatting.

All the test projects in my solution have the following packages:

The unit test provider is mstest.v2.

So far I have tried to clean the SpecFlow files in %TEMP%. I made sure that all projects have the same version of SpecFlow installed. I have cleaned the solution and done rebuilds. If I run the custom tool on each feature file individually I never get this problem.

I appreciate your help!

Upvotes: 3

Views: 642

Answers (1)

Amir
Amir

Reputation: 53

The issue was caused by projects with long names, nested folders and long test scenario descriptions. I shorten the scenario descriptions in one of the feature files that constantly had its behind code corrupted and the problem went away after that.

Upvotes: 1

Related Questions