SpecFlow icon indicating copy to clipboard operation
SpecFlow copied to clipboard

Generating the wrong NUnit Attributes

Open jtourvieille opened this issue 3 years ago • 1 comments

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 avatar Aug 12 '22 14:08 jtourvieille

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

jtourvieille avatar Aug 12 '22 14:08 jtourvieille