开发者

Multiple Multi-Line Examples in SpecFlow Feature File

This seems like one of those questions that, if you know the answer, it's obvious, and if you don't, it's impossible...

How do I include a table of multi-line examples in a SpecFlow feature 开发者_JAVA百科file?

My example would be:

        Given there is some invalid input:
        | input |
        | """ Multi-line example 1
              because there are multiple lines
              """ |
        | """Multi-line example 2
             with even more lines
             than the previous example
             """" |
    When something interesting happens
    Then the error is shown

Thanks in advance.


you can do it like this:

Given there is some invalid input:
    | <Here goes column Name> | <Column Name2..>  |
    | Line 1 for column 1     | Line 1 for column2|
    | Line 2 for column 1     | Line 2 for column2|
    | ..and so on             | and so on...      |
When something interesting happens
Then the error is shown

and this will be translate to

[Given(@"there is some invalid input:")]
public void GivenThereIsSomeInvalidInput(Table table)
{
   foreach (var row in table.Rows)
   {
       string info1= = row["<Here goes column Name>"];
       string info2= = row["<Column Name2..>"];
   }
}

and I understand you have a couple of sets of invalid input, well you could make another scenario, exactly like this, only add more input data in the table, no extra code needed.

Hope this solves your problem


Well, it looks like this isn't possible according to a poster in the Google SpecFlow group. He also points out that I may have too much implementation in my behavior test, and maybe this fits into unit tests more appropriately.


Since I do the comparison of actual and expected values myself (not using the automatic table comparison feature of SpecFlow), I allow using regular expressions for special values, like strings containing newline:

Then I expect the result values
    | Name            | Value              |
    | Multilinestring | @@Multline\nString |

And my compare function does this:

private static bool compare (string actual, string expected)
{
    if (expected.StartsWith("@@"))
        return Regex.Match(actual, expected.Substring(2)).Success;
    ....
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜