SpecFlowOSS / SpecFlow

#1 .NET BDD Framework. SpecFlow automates your testing & works with your existing code. Find Bugs before they happen. Behavior Driven Development helps developers, testers, and business representatives to get a better understanding of their collaboration

Home Page:https://www.specflow.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Step Argument Transformations run even if a previous step has failed.

shack05 opened this issue · comments

SpecFlow Version:

  • 3.7
  • 3.6
  • 3.5
  • 3.4
  • 3.3
  • 3.1
  • 3.0
  • 2.4
  • 2.3
  • 2.2
  • 2.1
  • 2.0
  • 1.9

Used Test Runner

  • SpecFlow+Runner
  • MSTest
  • NUnit
  • Xunit

Version number: nunit 3.13.0, NUnit3TestAdapter 3.17.0

Project Format of the SpecFlow project

  • Classic project format using packages.config
  • Classic project format using <PackageReference> tags
  • Sdk-style project format

.feature.cs files are generated using

  • SpecFlow.Tools.MsBuild.Generation NuGet package
  • SpecFlowSingleFileGenerator custom tool

Visual Studio Version

  • VS 2019
  • VS 2017

Enable SpecFlowSingleFileGenerator Custom Tool option in Visual Studio extension settings

  • Enabled
  • Disabled

Are the latest Visual Studio updates installed?

  • Yes
  • No, I use Visual Studio version <Major>.<Minor>.<Patch>

.NET Implementation:

  • .NET 5.0
  • .NET Core 3.1
  • .NET Core 2.1
  • >= .NET Framework 4.5
  • before .NET Framework 4.5

Test Execution Method:

  • Visual Studio Test Explorer
  • TFS/VSTS/Azure DevOps – Task – PLEASE SPECIFY THE NAME OF THE TASK
  • Command line – PLEASE SPECIFY THE FULL COMMAND LINE

<SpecFlow> Section in app.config or content of specflow.json

Not used

Issue Description

I'm not sure if this is a bug but I've noticed that Step Argument Transformations will run even if a previous step has already failed.
I would expect that step argument transformations will not run if a step is to be skipped.

Steps to Reproduce

Consider the following step definitions for the standard Calculator example:

    [Binding]
    public sealed class CalculatorStepDefinitions
    {
        [Given("the first number is (.*)")]
        public void SetFirstNumber(int number) { }

        [Given("the second number is (.*)")]
        public void SetSecondNumber(int number) { throw new Exception("Throwing on purpose"); }

        [When("the two numbers are (added|subtracted)")]
        public void WhenTheTwoNumbersAre(Operation operation) { }

        [Then("the result should be (.*)")]
        public void ThenTheResultShouldBe(int result) { }

        [StepArgumentTransformation]
        public Operation ParseOperation(string operand)
        {
            Console.WriteLine("Running step argument transformation.");
            // I know specflow can parse enums out of the box, but just using as an example
            return Enum.Parse<Operation>(operand, ignoreCase: true);
        }
    }

    public enum Operation
    {
        Added,
        Subtracted
    }

Note that the second step will throw an exception and the third step has a step argument transformation.
The output when running the scenario is:

Given the first number is 50
-> done: CalculatorStepDefinitions.SetFirstNumber(50) (0.0s)
And the second number is 70
-> error: Throwing on purpose (0.1s)
When the two numbers are added
Running step argument transformation.
-> skipped because of previous errors
Then the result should be 120
-> skipped because of previous errors

Repro Project

Here is a repro generated using the Specflow project template.

Ok, this is definitely a bug. This should not happen, as if you would have side effects in a step argument transformation (what you should never have), you will get into problems.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.