黄瓜重复步骤

时间:2014-12-11 11:45:18

标签: unit-testing cucumber

我正在学习黄瓜并试图写一个专题文件。

以下是我的专题文件。

  

功能:医生移交笔记模块

Scenario: Search for patients on the bases of filter criteria
Given I am on website login page
When I put username, password and select database:
  | Field        | Value        |
  | username     | test         |
  | password     | pass         |
  | database     | test|
Then I login to eoasis
Then I click on doctors hand over notes link
And I am on doctors handover notes page
Then I select sites, wards, onCallTeam, grades,potential Discharge, outstanding task,High priority:
  | siteList      | wardsList                     | onCallTeamList   | gradesList | potentialDischargeCB | outstandingTasksCB | highPriorityCB |
  | THE INFIRMARY | INFIRMARY WARD 9 - ASSESSMENT | null             | null       | null                 | null               | null           |
  | THE INFIRMARY | INFIRMARY WARD 9 - ASSESSMENT | GENERAL MEDICINE | null       | null                 | null               | null           |
  | THE INFIRMARY | INFIRMARY WARD 9 - ASSESSMENT | GENERAL MEDICINE | CONSULTANT | null                 | null               | null           |
  | THE INFIRMARY | INFIRMARY WARD 9 - ASSESSMENT | GENERAL MEDICINE | CONSULTANT | true                 | null               | null           |
  | THE INFIRMARY | INFIRMARY WARD 9 - ASSESSMENT | GENERAL MEDICINE | CONSULTANT | true                 | true               | null           |
  | THE INFIRMARY | INFIRMARY WARD 9 - ASSESSMENT | GENERAL MEDICINE | CONSULTANT | true                 | true               | true           |
Then I click on search button
Then I should see search results

我想重复最后三个步骤,例如我选择搜索条件,然后点击搜索按钮,然后检查搜索结果。那么我应该如何打破这个功能文件。如果我使用场景大纲,那么将有两个不同的场景一个用于登录,一个用于搜索条件。那很好吗?在这种情况下,会议是否会保持?什么是编写此类功能文件的最佳方式。

或者这是一种正确的写作方式吗?

2 个答案:

答案 0 :(得分:4)

我不认为我们可以在Scenario Outline中拥有多个示例集。 该示例中的大多数场景步骤过于程序化,无法拥有自己的步骤。 前三个步骤可以简化为类似的。

Given I am logged into eoasis as a <user>

步骤定义中的代码,可以调用单独的登录方法,该方法可以负责更新输入用户名,密码和选择数据库。

另一个规则是避免像#34;当我点击医生的移交链接时发表的声明&#34;。要避免点击这里的关键字。今天点击一下,明天它可以下拉或按钮。因此,焦点应该放在用户的功能期望上,即查看切换笔记。所以我们将其修改为

When I view the doctor's handover notes link

总结一下,这是我写这个测试的方式。

Scenario Outline: Search for patients on the basis of filter criteria
Given I am logged into eoasis as a <user>
When I view the doctor's handover notes link
And I select sites, wards, onCallTeam, grades, potential Discharge, outstanding task, High priority
And perform a search
Then I should see the search results

Examples: 
|sites          |wards                          |onCallTeam        |grades      |potential Discharge   |outstanding task    |High priority|
| THE INFIRMARY | INFIRMARY WARD 9 - ASSESSMENT | null             | null       | null                 | null               | null        |

答案 1 :(得分:1)

这实际上是编写功能的错误方法。这个功能非常具有说服力,它关于你如何做某事。功能应该做的就是解释为什么要做某事。

此功能的另一个坏处是混淆了两个不同操作的细节,登录和搜索患者。为每个人写一个特征,例如

Feature: Signing in
  As a doctor
  I want my patients data to only be available if I sign in
  So I ensure their confidentiality

Scenario: Sign in
  Given I am a doctor
  When I sign in
  Then I should be signed in

Feature: Search for patients
  Explain why searching for patients gives value to the doctor
  ...

您应该专注于功能的名称和顶部的位,以解释为什么它首先具有价值。如果你做得好,那么场景就更容易编写(看看我的签到场景有多简单)。

写作功能的艺术做得很好,所以你最终会得到简单的场景。

相关问题