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
https://www.specflow.org/
Other
2.24k stars 754 forks source link

Angle brackets are not parsed properly in scenario outline #1882

Open ikbendruk opened 4 years ago

ikbendruk commented 4 years ago

SpecFlow Version:

Used Test Runner

Version number: 3.8.1.0

Project Format of the SpecFlow project

.feature.cs files are generated using

Visual Studio Version

Enable SpecFlowSingleFileGenerator Custom Tool option in Visual Studio extension settings

Are the latest Visual Studio updates installed?

.NET Framework:

Test Execution Method:

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

  <specFlow>
    <unitTestProvider name="Nunit"/>
    <runtime missingOrPendingStepsOutcome="Error"/>
    <trace listener="UnitTests.SpecFlowTracer, UnitTests"/>
  </specFlow>

Repro Project

Issue Description

When executing the following scenario outline

Scenario Outline: Less than works as expected
    Given 5 <= <x>

    Examples:
    | x |
    | 5 |

with the following step implementation

[Given(@"(.*) \<\= (.*)")]
public void Given(int p0, int p1)
{
    Assert.IsTrue(p0 <= p1);
}

SpecFlow generates the following NUnit code

[NUnit.Framework.TestAttribute()]
[NUnit.Framework.DescriptionAttribute("Less than works as expected")]
[NUnit.Framework.TestCaseAttribute("5", null)]
public virtual void LessThanWorksAsExpected(string x, string[] exampleTags)
{
    TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Less than works as expected", exampleTags);
#line 7
this.ScenarioSetup(scenarioInfo);
#line 8
    testRunner.Given("5 <= <x>", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given ");
#line hidden
    this.ScenarioCleanup();
}

Parameter x is not parsed properly that's why the test fails.

[12:41:06.900] Given 5 <= <x>
[12:41:06.925] error: Input string was not in a correct format

Steps to Reproduce

  1. Run the scenario outline described above.
SabotageAndi commented 4 years ago

Interesting issue. We recommend putting parameters of your steps in single quotes '. This makes it easier for a human and also our logic to recognize what are parameters in the step.

So your step would look like Given '5' <= '<x>'

ikbendruk commented 4 years ago

So your step would look like Given '5' <= '<x>'

Thanks for the tip!

Unfortunately, this does not work very well for me since my steps look more like:

Then parameter <Parameter> value remains equal to or less than <Value> for <Timeout> seconds

The idea was to make these steps shorter and more readable with <=, >=.

I also tried special symbols ≤, ≥. They work perfectly fine with SpecFlow but are not properly displayed in the console output. So this option does not help either.