Name generation for scenario outlines

849 views
Skip to first unread message

DannyBraig

unread,
Oct 21, 2016, 6:45:13 AM10/21/16
to SpecFlow
Hello everyone,
I'm currently trying out the 'scenario outlines'.

I'm wondering about the testname-generation in in such a case.
According to the documentation:

For better traceability, the generated unit test method names are derived from the scenario outline title and the first value of the examples (first column of the examples table). It is therefore good practice to choose a unique and descriptive parameter as the first column in the example set. As the Gherkin syntax does require all example columns to have matching placeholders in the scenario outline, you can even introduce an arbitrary column in the example sets used to name tests with more readability.

Like this, I have definded the following dummy-scenario:

 
Scenario Outline: Some Scenario
When I am doing <x>
Then  the action <y> happens

Examples: 
| description | x | y |
| testcase1   | 1 | 1 |
| testcase2   | 2 | 2 |

I'd expect the UnitTest Name now to be shown as SomeScenario_testcase1 

But actually it shows like SomeScenario("testcase1","1","1",System.String[] ).

Am I doing something wrong here? 
Is there another way to properly "rename" my testcases generated by scenario outlines?

Thanks in advance...
Daniel

Andreas Willich

unread,
Oct 21, 2016, 7:17:09 AM10/21/16
to SpecFlow
Hi Daniel

This depends on your unit test provider. Which one are you using? MsTest, XUnit, NUnit2/NUnit3, SpecFlow+Runner?

Best regards
Andreas

--
You received this message because you are subscribed to the Google Groups "SpecFlow" group.
To unsubscribe from this group and stop receiving emails from it, send an email to specflow+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

DannyBraig

unread,
Oct 21, 2016, 7:27:36 AM10/21/16
to SpecFlow
Hi Andreas,
sorry.. I forgot to mention that.
I am using NUnit 3 as unit test provider... 

Andreas Willich

unread,
Oct 21, 2016, 10:30:08 AM10/21/16
to SpecFlow
Ok, interessting.
So SpecFlow works in the way, that it generates coded tests with the appropriate attributes.
The test runners take that information and display you the tests.

In your case it could be that
1.) the code generation for NUnit3 has something (I don't believe that)
2.) your test runner reads the attributes in a strange way and creates strange test names for it.

Which one are you using?
The Visual Studio Adapter for the test explorer?
The R# Testrunner?
Console testrunner?


DannyBraig

unread,
Oct 24, 2016, 2:58:26 AM10/24/16
to SpecFlow
Hi Andreas,

I am using the Visual studio Adapter for the test explorer, yes.
I have installed in "extensions and updates":
  • Nunit 3 Test adapter
  • SpecFlow for Visual Studio 2015
What could be the issue? 
Can you please help me find a fix..? :-)

Thanks!

DannyBraig

unread,
Oct 24, 2016, 8:52:01 AM10/24/16
to SpecFlow
I have noticed one more thing...

the example i posted above generates to the following Nunit3 code:

  [NUnit.Framework.TestAttribute()]
        [NUnit.Framework.DescriptionAttribute("Some Scenario")]
        [NUnit.Framework.TestCaseAttribute("testcase1", "1", "1", new string[0])]
        [NUnit.Framework.TestCaseAttribute("testcase2", "2", "2", new string[0])]
        public virtual void SomeScenario(string description, string x, string y, string[] exampleTags)
        {
            TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Some Scenario", exampleTags);
#line 6
this.ScenarioSetup(scenarioInfo);
#line 7
testRunner.When(string.Format("I am doing {0}", x), ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When ");
#line 8
testRunner.Then(string.Format("the action {0} happens", y), ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then ");
#line hidden
            this.ScenarioCleanup();
        }

..
When i am looking at NUnit 3's documentation it says about "TestCase" the following:

TestName provides a name for the test. If not specified, a name is generated based on the method name and the arguments provided.

So i think the behavior of NUnit is correct.. right?

Andreas Willich

unread,
Oct 24, 2016, 11:48:18 AM10/24/16
to SpecFlow
We changed something at the attributes for NUnit3 with 2.2.
Could you try it out? It is available as a prerelease package on NuGet.org.

@Dirk: Do you have any idea about this?

DannyBraig

unread,
Oct 25, 2016, 10:52:28 AM10/25/16
to SpecFlow
Hi Andreas,

thanks for helping me.

I got the new Package (V2.2), but still the test shows as "SomeScenario("testcase1","1","1",System.String[] )"...

Any more suggestions on this?
What else should I try out? :-( 
Thanks in advance.

Dirk Rombauts

unread,
Oct 27, 2016, 9:55:25 AM10/27/16
to SpecFlow
I changed the generation of the Ignore attribute in NUnit3, but nothing about Scenario Outlines ... sorry.

Dirk

DannyBraig

unread,
Oct 28, 2016, 3:33:57 AM10/28/16
to SpecFlow
Hi everyone,

what does this mean for my current issue?

Is it an issue with the test-generation? Should i raise an issue on github? :-( 
Or am i doing something wrong..? 

Thanks,

Daniel

Manoj Kapuganti

unread,
Jan 15, 2018, 1:19:12 PM1/15/18
to SpecFlow
Hi,

Please let me know if you found any solution about this.

Thanks in advance.
Message has been deleted

Andreas Willich

unread,
Oct 13, 2020, 9:03:56 AM10/13/20
to SpecFlow

I think this is the way NUnit Scenarios are displayed. As far as I remember we tried to improve it (https://github.com/SpecFlowOSS/SpecFlow/pull/1874), but there was/is a problem with the test adapter, so we need to take the change back.

The SpecFlow+ Runner and xUnit have as far as I remember better test/method names in the test explorer for Scenario Outlines.

On Tue, Oct 13, 2020 at 2:43 PM Martin K <martin...@gmail.com> wrote:
I'm having exactly the same problem with Specflow and Nunit3. My scenario outlines test names look like:

NP10_New_Record_Details_Tab_Info("Prod010a","Product 010a","01/10/2020","10.00",null)  

I need to make them more readable than listing every column of the Example table row in the test name
Was there a solution to this?

--
You received this message because you are subscribed to the Google Groups "SpecFlow" group.
To unsubscribe from this group and stop receiving emails from it, send an email to specflow+u...@googlegroups.com.

Martin K

unread,
Oct 13, 2020, 9:21:03 AM10/13/20
to SpecFlow
Thanks Andreas - sorry for the multiple posts, was trying to spread the topic and didnt realise you would answer all. Regards.
Reply all
Reply to author
Forward
0 new messages