meshier
meshier

Reputation: 145

Specflow test using example table shows null parameter in test runner

I have the following specflow scenario:

Scenario: CasingMentions
    When User mentions everyone with <casing> casing
    Then user should be able to see the message they just sent
    Examples: 
    | casing |
    | lower  |
    | mixed  |
    | upper  |

The step definition is like this, and the method just takes a single string:

[When(@"User mentions everyone with (.*) casing")]

this runs completely fine and everything, but in the test runner on visual studio, it shows that there's a null parameter, so the above scenario will appear in the test runner as 3 separate tests, with names like this:

CasingMentions("lower",null)
CasingMentions("mixed",null)
CasingMentions("upper",null)

In the feature.cs file, this is what it looks like:

    [NUnit.Framework.TestAttribute()]
    [NUnit.Framework.DescriptionAttribute("CasingMentions")]
    [NUnit.Framework.TestCaseAttribute("lower", null)]
    [NUnit.Framework.TestCaseAttribute("mixed", null)]
    [NUnit.Framework.TestCaseAttribute("upper", null)]
    public virtual void CasingMentions(string casing, string[] exampleTags)
    {

I don't think its related to the step definition because I can paste the examples into a scenario that takes no parameters, and it will still do this

Here is a video that shows the problem I am encountering: https://youtu.be/vC87WMFfJ4Y?t=438

Is there any way to get rid of the null? This happens for every single scenario I use example tables for, and it doesn't seem to make a difference if I use scenario or scenario outline. I am using NUnit as my test runner if that matters.

I have also tried adding an extra column with unique values to try to name the test cases that way, but they just appear as another parameter in the bracket.

Upvotes: 6

Views: 1648

Answers (1)

codingjoe
codingjoe

Reputation: 810

I found out there is not a way to get rid of the last 'null'. The last parameter is used for tags regarding your examples.

MyTest("AA","40","11","mysite.com","ENG","+662154215","HotchocolateService","[email protected]","Insurance","2", null)

if you put a @important tag on your examples:

 @important
    Examples: | data | data2 |

It will be parsed in the testcase attribute:

MyTest("AA","40","11","mysite.com","ENG","+662154215","HotchocolateService","[email protected]","Insurance","2",["important"])

The important tag can be used in regards of prioritizing som testcases to run prior to others.

Upvotes: 2

Related Questions