首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Gherkin表-删除重复

Gherkin表-删除重复
EN

Stack Overflow用户
提问于 2018-06-11 06:56:12
回答 4查看 701关注 0票数 1

我有一个黄瓜gherkin功能文件如下所示:

代码语言:javascript
复制
Feature: Log in

  Scenario Outline: Successful log-in
     Given i enter <username>
     Given and password <password>
     Then I log in

     Examples:
       | username | password |
       | hello | sorry |
       | hello | hello |
       | hello | goodbye |
       | admin | sorry |
       | admin | hello |
       | admin | goodbye |

正如您在上面的用户名和密码表中看到的,有很多重复。我怎样才能消除这种重复?

例如,我可以创建两个特性,如

(1)

代码语言:javascript
复制
Feature: Log in

  Scenario Outline: Successful log-in
     Given i enter hello
     Given and password <password>
     Then I log in

     Examples:
       | password |
       | sorry |
       | hello |
       | goodbye |

(2)

代码语言:javascript
复制
Feature: Log in

  Scenario Outline: Successful log-in
     Given i enter admin
     Given and password <password>
     Then I log in

     Examples:
       | password |
       | sorry |
       | hello |
       | goodbye |

但这里还是有重复的。

有没有其他方法来删除这个重复。我想要的是:

代码语言:javascript
复制
Feature: Log in

  Scenario Outline: Successful log-in
     Given i enter <username>
       | hello |
       | admin |
     Given and password <password>
       | sorry |
       | hello |
       | goodbye |
     Then I log in

但我不确定这类事情是否可能.

PLease帮我..。

我在这里省略了步骤定义,因为它们很容易完成。

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2018-06-13 15:50:43

总之,没有。没有一种方法可以将Examples表中的示例相乘。

但是,还有一种方法可以提高可读性,并提高业务对测试的理解(这正是您真正希望使用BDD风格的测试)。

代码语言:javascript
复制
Background:
  Given I am on the login page

Scenario Outline: Logging in with valid passwords
  When I attempt to log in as <user_type> with a valid password
  Then I should see the <page> page

 Examples:
    | user_type | page            |
    | a user    | home            |
    | an admin  | admin dashboard |

Scenario Outline: Logging in with invalid passwords
  When I attempt to log in as <user_type> with an invalid password
  Then I should see the password validation

 Examples:
   | user_type |
   | a user    |
   | an admin  |

Background可以消除设置步骤的重复(假设它们在特性中的所有场景中都是相同的),并且如果您将每个场景大纲按它试图实现的目标分组,那么您应该具有更好的可读性,测试的目的是明确表达的。

票数 2
EN

Stack Overflow用户

发布于 2018-06-13 16:34:35

我没有比“凯尔-仙女”更好的答案了。

但为了完整起见,您的场景可能过于简化(这可能掩盖了您的真实意图)。

  • 使用标签或环境/world变量以不同的参数运行完全相同的场景。
  • 生成成对的测试表,如下所述:http://blog.josephwilk.net/ruby/pairwise-testing-with-cucumber.html
票数 0
EN

Stack Overflow用户

发布于 2018-07-02 07:34:02

我为它开了一期https://github.com/cucumber/cucumber-js/issues/1105,但它被关闭了:

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50791957

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档