specflow - Gherkin Scenario Outline 多次使用同一张表
问题描述
我正在为 Visual Studio 编写 Specflow 中的场景大纲。目的是测试人名比较器功能,以便在两者之间选择最佳名称。
就我而言,我有属于名称和外部属性的属性,它们属于 Person 实体。比较流程分为两部分:首先我检查人员(姓名的所有者)的属性以决定,如果这没有产生结果(意味着他们的属性相同),然后我检查姓名的属性. 我已经为名称的属性比较编写了单独的测试,所以在这个测试中我只关心 Person 属性和名称之间的关系——可以是Name1 < Name2
:Name1 > Name2
或Name1 ≡ Name2
.
到目前为止,我已经为这三个案例中的每一个编写了一个场景大纲,因为我需要为每个案例运行Examples
表中的每个参数一次。
代码看起来像这样:
Scenario Outline: Comparing names
Given I have a first name <name1>
And the first person has properties <properties1>
And I have a second name <name2>
And the second person has properties <properties2>
When I choose the best name
Then the best name should be <best name>
Examples:
| properties1 | properties2 |
| FirstName:"Carlos" | FirstName:"Johny" |
| LastName:"Smith" | FirstName:"Johny" |
| FirstName:"John",LastName:"Smith" | LastName:"Smith" |
现在代替名称,我写了 3 次,每次为名称之间的关系写一次,我在场景中硬编码了名称。
理想情况下,我希望有一个表,以便能够有一个与表的每一行一起运行的主要参数。
知道如何在没有三个不同的场景大纲的情况下实现它吗?
解决方案
用于创建每个人的 SpecFlow 表可能是理想的解决方案。这允许您传递每个名称的值或空值:
Scenario Outline: Comparing names
Given I have a first name <name1>
And the first person has properties:
| Field | Value |
| First Name | <first name 1> |
| Last Name | <last name 1> |
And I have a second name <name2>
And the second person has properties:
| Field | Value |
| First Name | <first name 2> |
| Last Name | <last name 2> |
When I choose the best name
Then the best name should be <best name>
Examples:
| name1 | first name 1 | last name 1 | first name 2 | last name 2| best name |
| X | Carlos | | Johnny | | X |
| X | | Smith | Johnny | | X |
| X | John | Smith | | Smith | X |
这种方法的优点是您可以扩展为每个人设置的属性。
推荐阅读
- python - TypeError: 'function' 类型的对象没有 len() - 我该如何解决这个错误?
- html - 盒子阴影插入填充留下未填充的边缘?
- angular - 角度对象映射返回与数字相反的字符串
- java - 需要了解 buildSrc Gradle 项目中的这段 Kotlin 代码
- vue.js - vue .net 核心应用中的 Vuex
- refresh - 在 Dynamics 365 CRM 统一接口中重新加载/刷新子网格时重新加载表单的问题
- azure - 在 Azure 解决方案中更改资源组
- c# - 在 C# 中调用 arcgis rest 服务时出现 500 内部服务器错误
- java - 使用 Java 将当前日期与 MySQL DB 中的日期进行比较
- reactjs - ComponentDidMount 导致我的服务器崩溃