Search code examples
c#visual-studio-2012specflow

How do I generate a List<T> in the step definition of a SpecFlow Scenario?


In the documentation for SpecFlow Step Definitions it shows an example where you can create a list in the step definition by using a comma separated list in the scenario:

For example:

Given I am available on "Tuesday,Friday,Sunday"

would result in:

@Given("I am available on \"(.+)\"")
public void I_have_cukes_in_my_belly(List<String> days) {
    // Do something with the days
}

Unfortunately, when I do it, I get this:

@Given("I am available on ""(.*)"")
public void I_have_cukes_in_my_belly(string days) {
    // Do something with the days
}

I am using VS 2012 and version 1.9.1 of SpecFlow. Does anyone have any idea what I might be doing wrong? Or how I can go about fixing this?

Thanks in advance.


Solution

  • The only language that seems to support Lists currently is Java. I'm assuming you're using C# as you're using VS2012. If you switch the code sample on your linked page to C# instead of Java, the List example goes away and I'm seeing the same behavior you are.

    However, you can simply get the string as a parameter and put it into a List. 1 line.

    C#

    [Given(@"I am available on ""(.*)""")]
    public void GivenIAmAvailableOn(string days)
    {
            List<String> daysList = new List<string>(days.Split(','));