Specflow测试步骤继承会导致“模棱两可的步骤定义”。 [英] Specflow test step inheritance causes "Ambiguous step definitions"

查看:86
本文介绍了Specflow测试步骤继承会导致“模棱两可的步骤定义”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想具有以下测试步骤类结构:

I want to have the following test step class structure:

[Binding]
public class BaseStep
{
    [Given(@"there is a customer")]
    public void GivenThereIsACustomer(Table table)
    {
        HandleCustomer(table);
    }

    protected virtual void HandleCustomer(Table table)
    {
    }
}

[Binding]
public class FeatureOneStep : BaseStep
{
    protected override void HandleCustomer(Table table)
    {
         // feature one action
    }

    [Given(@"feature one specific step")]
    public void GivenFeatureOneSpecificAction(Table table)
    {
        // do something
    }

}

[Binding]
public class FeatureTwoStep : BaseStep
{
    protected override void HandleCustomer(Table table)
    {
         // feature two action
    }

    [Given(@"feature two specific step")]
    public void GivenFeatureTwoSpecificAction(Table table)
    {
        // do something
    }
}

给有客户是一个常见步骤在FeatureOne和FeatureTwo中都使用了它,但是它会有不同的ha将逻辑包含在两个功能中。因此,我决定将此步骤定义放入基类中,并分别在两个派生类中重写受保护的方法。

"Given there is a customer" is a common step that is used in both FeatureOne and FeatureTwo, but it will have different handling logic inside the two features. So I decide to put this step definition into a base class and override the protected methods in two derived classes respectively.

但是,当我运行测试时,我有以下内容错误:

However, when I ran the tests, I have the following error:

TechTalk.SpecFlow.BindingException: Ambiguous step definitions found for step
'Given there is a customer': 
CustomerTestBase.GivenThereIsACustomer(Table),   
CustomerTestBase.GivenThereIsACustomer(Table)

有人可以告诉我如何解决此问题吗?

Can any one tell me how to fix this issue?

推荐答案

我自己现在已经弄清楚了,所以有几点注意(希望有人将来可以使用它):

Just figuring this out now myself, so a couple of notes (hopefully somebody can use this in the future):


  • 在基类上不要包含[Binding]属性

  • 为每个功能文件创建一个派生类


    • 将[Binding]属性添加到派生类中(将自动在基本类)

    • 添加[Scope]属性te到派生类;为命名参数Feature指定功能的名称

    这篇关于Specflow测试步骤继承会导致“模棱两可的步骤定义”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆