【问题标题】:TechTalk.SpecFlow.BindingException: 'Parameter count mismatch! The binding methodTechTalk.SpecFlow.BindingException:'参数计数不匹配!绑定方法
【发布时间】:2020-06-02 17:59:21
【问题描述】:

我正在尝试为 specflow 编写 StepArgumentTransformation。

我有关注小黄瓜

Scenario: Test Arguments
Given user enter once as 2

我已经在步骤定义中写了这个。

    [StepArgumentTransformation]
    public int GetOnces(string onces, string times)
    {
        return 1 * int.Parse(times);
    }

    [Given(@"user enter (.*) as (.*)")]
    public void GivenUserEnterOnce(int num)
    {
        Assert.Equal(2, num);
    }

但是 GetOnces 方法从未被调用,我得到了异常

TechTalk.SpecFlow.BindingException: '参数计数不匹配!绑定方法'GivenUserEnterOnce(Int32)'应该有2个参数

【问题讨论】:

    标签: c# specflow gherkin


    【解决方案1】:

    绑定应该是这样的:

    [StepArgumentTransformation("(.*) as (.*)")]
    public int GetOnces(string onces, string times)
    {
        return 1 * int.Parse(times);
    }
    
    [Given(@"user enter (.*)")]
    public void GivenUserEnterOnce(int num)
    {
        Assert.Equal(2, num);
    }
    

    如果要转换多个参数,则必须在 StepArgumentTransformation 中指定正则表达式。你真正的步骤只得到一个参数,所以正则表达式中只有一个参数是有效的。

    您可以在此处找到相关文档:https://specflow.org/documentation/Step-Argument-Conversions/

    【讨论】:

      【解决方案2】:

      对我来说,问题只是我忘记/删除了场景中的“Then”行

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-01-10
        • 2011-02-10
        • 1970-01-01
        • 2017-12-31
        • 2012-06-17
        • 1970-01-01
        相关资源
        最近更新 更多