在小黄瓜中处理/传递特征文件中的多个参数

问题描述 投票:0回答:2

如何使用功能传递多个参数。

我知道“示例:”概念的用法,但它以某种方式使功能文件变得更加复杂和不可读

示例:

Scenario Outline: To verify that default value for some timeout when invalid/remove is set for some timeout parameter

When <parameterA> is <action> with <parameterB> for <someOtherParameterPair> in <fileName>
Then <parameterA> is updated with value <parameterB> for <someOtherParameterPair> in <fileName> as per defined <action>
Examples:
|parameterA  |parameterB  |action|someOtherParameterPair|fileNameWithSectionName|
|oneParameter|twoParameter|update|key:Value             |abc.config:appSettings |
|oneParameter|twoParameter|delete|key:Value             |def.config:appSettings |

这里,我有大约 7 个来自测试用例的参数(由于限制,我尝试将其容纳在 5 个参数中)

我将使用步骤定义文件中的 split 将“someOtherParameterPair”和“fileNameWithSectionName”分成两部分。所以总共我有大约 7 个参数将在测试用例中使用。

但我不确定从Given/When/Then语句中接受如此大量的参数是否可行。这也使我的测试用例难以阅读。

在上面的场景中,我试图修改某些位置的 *.config 文件中存在的一些参数(我从功能文件传递这些参数,以便我的 When/Then 语句可以修改)。

之后我需要执行测试用例。

以同样的方式,我的测试套件中还有其他(大多数)案例。

请帮助我是 BDD 的正确方法。 BDD 是否会在维护中产生一些问题,因为我看到了很多内容(几乎来自功能文件的所有内容)。

c# automation bdd acceptance-testing gherkin
2个回答
0
投票

答案是不要这样写你的特征。不要使用您的功能来描述

how
您正在测试某些内容,而是用它来解释
what
您正在测试以及
why
您正在测试它

一般来说,这意味着您不需要使用示例,并且您当然永远不需要像现有的那样使用复杂的示例。您始终可以将示例的使用降低到较低级别,例如步骤定义。

在这种情况下,您似乎应该编写单元测试。此场景中没有描述任何商业价值。

BDD 是关于描述行为并使用它来驱动开发。写完之后就不能用它来测试!!


0
投票

示例表不应超过 3 列。否则,就不可能理解列之间的关系、测试方法、测试目标并分析测试结果。

您需要澄清测试目标才能重构它。 可能的优化步骤:

  1. 如果您测试某些参数在某些情况下从值
    oneParameter
    更改为
    twoParameter
    ,那么出现
    <parameterA>
    列的原因是什么?如果要覆盖该参数,则其先前的值并不重要,您可以忽略它。
  2. someOtherParameterPair
    fileNameWithSectionName
    之间有什么关系?您真的需要在表中分隔这些列吗?也许你可以将它们组合成
    <pathToTheParameterPair>

根据上述假设,您的场景可以简化如下:

Scenario Outline: To verify that default value for some timeout when invalid/remove is set for some timeout parameter

When SettingName is <action> with <parameterB> for <pathToTheParameterPair> 
Then SettingName is updated with value <parameterB> for <pathToTheParameterPair> as per defined <action>
Examples:
| parameterB   |action | pathToTheParameterPair |
| twoParameter |update | abc.config:appSettings:key:Value |
| twoParameter |delete | def.config:appSettings:key:Value |
© www.soinside.com 2019 - 2024. All rights reserved.