SpecFlow功能文件中的多个多行示例。

| 这似乎是这些问题之一,如果您知道答案,那是显而易见的;如果您不知道,那是不可能的... 如何在SpecFlow功能文件中包含多行示例表格? 我的例子是:         鉴于存在一些无效的输入:         |输入|         | \“ \” \“多行示例1               因为有多行               \“ \” \“ |         | \“ \” \“多行示例2              与更多的行              比前面的例子              \“ \” \“ \” |     当一些有趣的事情发生时     然后显示错误 提前致谢。     
已邀请:
        您可以这样做:
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
这将被转换为
[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..>\"];
   }
}
而且我知道您有几组无效的输入,那么您可以制作另一种情况,就像这样,只在表中添加更多输入数据,不需要额外的代码。 希望这能解决您的问题     
        嗯,根据Google SpecFlow组中的张贴者看来,这是不可能的。他还指出,我的行为测试可能实施过多,也许更适合单元测试。     
        由于我自己进行了实际值和期望值的比较(不使用SpecFlow的自动表比较功能),因此我允许对特殊值使用正则表达式,例如包含换行符的字符串:
Then I expect the result values
    | Name            | Value              |
    | Multilinestring | @@Multline\\nString |
我的比较功能可以做到这一点:
private static bool compare (string actual, string expected)
{
    if (expected.StartsWith(\"@@\"))
        return Regex.Match(actual, expected.Substring(2)).Success;
    ....
}
    

要回复问题请先登录注册