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

Generating the wrong NUnit Attributes #2636

Open jtourvieille opened 2 years ago

jtourvieille commented 2 years ago

SpecFlow Version

3.9.40

Which test runner are you using?

NUnit

Test Runner Version Number

3.13.2

.NET Implementation

.NET 6.0

Project Format of the SpecFlow project

Classic project format using <PackageReference> tags

.feature.cs files are generated using

SpecFlow.Tools.MsBuild.Generation NuGet package

Test Execution Method

Visual Studio Test Explorer

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

No response

Issue Description

The TestCaseAttribute is not generated over the test method by SpecFlow generator. Instead, the DescriptionAttribute is generated. But, when having spaces in the scenario name, the name of the method is taken into account to generate the test name, not the DescriptionAttribute.

Actually, it works like this: Scenario name = "My scenario name" which generates MySampleScenario method with [NUnit.Framework.DescriptionAttribute("My scenario name")] attribute. which generates a test "MyScenarioName" final test name.

What I would expect is: Scenario name = "My scenario name" which generates MySampleScenario method with [NUnit.Framework.TestCase(TestName = "My scenario name")] attribute. which generates a test "My Scenario Name" final test name.

Note that the exact same issue exists at the class level.

Thanks!

Steps to Reproduce

Add a simple .feature file with spaces in the scenario name or feature name, build and see the test name output

Link to Repro Project

No response

jtourvieille commented 2 years ago

problem seems to be in this class: https://github.com/SpecFlowOSS/SpecFlow/blob/master/TechTalk.SpecFlow.Generator/UnitTestProvider/NUnit3TestGeneratorProvider.cs