【问题标题】:How to ignore alphanumeric text in Specflow statement from being transformed to parameter?如何忽略 Specflow 语句中的字母数字文本从转换为参数?
【发布时间】:2020-10-20 19:30:08
【问题描述】:

我正在创建一个 SpecFlow 场景(使用 Visualt Studio),其中字母数字文本是语句的一部分。
但是当我创建它的定义时,字母数字文本的数字部分变为参数。例如

Scenario: Add two variables
Given the first number is of type S1 and is 50
And the second number is of type S2 and is 70
When the two numbers of type S1 and S2 are added
Then the result should be 120

当我右键单击 Given 语句并创建定义时,我得到以下定义:

[Given(@"the first number is of type S(.*) and is (.*)")]
public void Function(int p0, int p1)

我想要的是:

[Given(@"the first number is of type S1 and is (.*)")]
public void Function(int p0)

【问题讨论】:

    标签: c# specflow


    【解决方案1】:

    SpecFlow 在为步骤定义生成存根时猜测正则表达式应该是什么。步骤中出现的任何数字都被猜测为参数。这是默认行为,我不知道如何更改它。只需修改步骤定义模式,使其适合您的特定用例。

    【讨论】:

    • 是的,在这些情况下,您必须手动更改正则表达式。扩展试图尽可能好地猜测什么是参数,什么不是。不能保证它总是会创建你想要的正则表达式。
    猜你喜欢
    • 2014-08-20
    • 1970-01-01
    • 2023-01-31
    • 1970-01-01
    • 1970-01-01
    • 2013-03-31
    • 1970-01-01
    • 2014-03-13
    • 1970-01-01
    相关资源
    最近更新 更多