为什么specflow没有作为参数传递到表中?

时间:2015-09-23 00:39:53

标签: c# bdd specflow

我有以下(小黄瓜)场景大纲(使用Specflow v1.9):

Scenario Outline: Add section title to report

Given I have "<section titles>" in a form:
When I edit the layout of the XX page
Then I should see the "<section titles>" as available columns for customizing the layout
When I add  "<section titles>" to the list of selected columns
And save the changes
Then the "<section titles>" are added to the report
And shows a color-coded view of the total applicant score categorized as follows:
| score_min | score_max | color  |
| 0         | 25        | red    |
| 25        | 75        | yellow |
| 75        | 100       | green  |


Examples:
| section titles |
| MyTitle1       |
| MyTitle2       |

然而,在最后&#34;和&#34;步骤定义,表永远不会在参数中传递。这是Specflow生成的代码:

[Then(@"shows a color-coded view of the total applicant score categorized as follows:")]
public void ThenShowsAColor_CodedViewOfTheTotalApplicantScoreCategorizedAsFollows()
{
   //Note missing 'Table' in argument
    ScenarioContext.Current.Pending();
}

但是,自动生成的功能文件代码隐藏似乎有此表,但它不属于我的步骤定义:

#line hidden
            TechTalk.SpecFlow.Table table1 = new TechTalk.SpecFlow.Table(new string[] {
                        "score_min_percentage_equal_to",
                        "score_max_percentage_less_than_or_equal_to",
                        "color"});
            table1.AddRow(new string[] {
                        "0",
                        "25",
                        "red"});
            table1.AddRow(new string[] {
                        "25",
                        "75",
                        "yellow"});
            table1.AddRow(new string[] {
                        "75",
                        "100",
                        "green"});
#line 14
testRunner.And("shows a color-coded view of the total applicant score categorized as follows:", ((string)(null)), table1, "And ");
#line 19

它看起来像#34;应该&#34;是步骤定义的表参数,但在生成步骤时似乎缺少它。我错过了什么?

更新:2016年5月13日:错误由Specflow开发人员提出并解决:https://github.com/techtalk/SpecFlow/issues/487

1 个答案:

答案 0 :(得分:-1)

如果没有示例表,则场景大纲本身是无用的,并且只有示例可以与场景大纲一起使用。如果我们谈论幕后,示例中的每一行都会转换为单个场景。正如Sam建议的那样,我们必须在方法定义中手动输入参数。