语法

The primary keywords are:

  • Feature
  • Rule (as of Gherkin 6)
  • Scenario (or Example)
  • Given, When, Then, And, But (steps)
  • Background
  • Scenario Outline (or Scenario Template)
  • Examples (or Scenarios)

There are a few secondary keywords as well:

  • """ (Doc Strings)
  • | (Data Tables)
  • @ (Tags)
  • # (Comments)

举例

Feature: Some terse yet descriptive text of what is desired
In order to realize a named business value
As an explicit system actor
I want to gain some beneficial outcome which furthers the goal Scenario: Some determinable business situation
Given some precondition
And some other precondition
When some action by the actor
And some other action
And yet another action
Then some testable outcome is achieved
And something else we can check happens too Scenario: A different situation
...

And/But

And/But作为Given/When/Then的同义词使用,

如Given x, And y 这里的And等同于之前的Given,以增加可读性。

Background

Feature: Multiple site support
Only blog owners can post to a blog, except administrators,
who can post to all blogs. Background:
Given a global administrator named "Greg"
And a blog named "Greg's anti-tax rants"
And a customer named "Dr. Bill"
And a blog named "Expensive Therapy" owned by "Dr. Bill" Scenario: Dr. Bill posts to his own blog
Given I am logged in as Dr. Bill
When I try to post to "Expensive Therapy"
Then I should see "Your article was published." Scenario: Dr. Bill tries to post to somebody else's blog, and fails
Given I am logged in as Dr. Bill
When I try to post to "Greg's anti-tax rants"
Then I should see "Hey! That's not your blog!" Scenario: Greg posts to a client's blog
Given I am logged in as Greg
When I try to post to "Expensive Therapy"
Then I should see "Your article was published."

Tips for using Background

  • Don’t use Background to set up complicated states, unless that state is actually something the client needs to know.

    • For example, if the user and site names don’t matter to the client, use a higher-level step such as Given I am logged in as a site owner.
  • Keep your Background section short.
    • The client needs to actually remember this stuff when reading the scenarios. If the Background is more than 4 lines long, consider moving some of the irrelevant details into higher-level steps.
  • Make your Background section vivid.
    • Use colourful names, and try to tell a story. The human brain keeps track of stories much better than it keeps track of names like "User A", "User B", "Site 1", and so on.
  • Keep your scenarios short, and don’t have too many.
    • If the Background section has scrolled off the screen, the reader no longer has a full overview of whats happening. Think about using higher-level steps, or splitting the *.feature file.

Scennario Template

The keyword Scenario Template is a synonym of the keyword Scenario Outline.

A Scenario Outline must contain an Examples (or Scenarios) section.

Scenario Outline: eating
Given there are <start> cucumbers
When I eat <eat> cucumbers
Then I should have <left> cucumbers Examples:
| start | eat | left |
| 12 | 5 | 7 |
| 20 | 5 | 15 |

Refer

https://cucumber.io/docs/gherkin/reference/

gherkin的更多相关文章

  1. Gherkin学习笔记

    前言 由于项目准备使用BDD模式开发,所以最近在学习BDD,同时也记录下自己的学习点滴. 参考原文:https://github.com/cucumber/cucumber/wiki/Gherkin ...

  2. Cucumber 之Gherkin

     1.Gherkin简介: Cucumber是一个解释程序,就像ruby命令执行解释 .rb文件里的Ruby代码一样,Cucumber用来执行解释 .feature文件里的Gehrkin代码. 2. ...

  3. Gherkin关键字

    Feature 功能 Background 背景 Scenario 场景 Outline Scenarios(or Examples) Given 假如.假设.假定 When 当 Then 那么 An ...

  4. 如何使用RobotFramework编写好的测试用例

    如何使用Robot Framework编写优秀的测试用例 概述 命名 测试套件命名 测试用例命名 关键字命名 setup和teardown的命名 文档 测试套件文档 测试用例文档 用户关键字文档 测试 ...

  5. Java资源大全中文版(Awesome最新版)

    Awesome系列的Java资源整理.awesome-java 就是akullpp发起维护的Java资源列表,内容包括:构建工具.数据库.框架.模板.安全.代码分析.日志.第三方库.书籍.Java 站 ...

  6. DotNet 资源大全中文版(Awesome最新版)

    Awesome系列的.Net资源整理.awesome-dotnet是由quozd发起和维护.内容包括:编译器.压缩.应用框架.应用模板.加密.数据库.反编译.IDE.日志.风格指南等. 算法与数据结构 ...

  7. Cucumber(一): Preparation

    Every time I wrote some code in ruby and executed our cucumber features I craved for something simil ...

  8. Cucumber测试驱动开发

     Cucumber是一种BDD实践开发工具,属于敏捷开发的组成部分.      在敏捷开发中,对用户进行需求分析时,不是像传统的P&D的开发方式,首先编写大量的用户需求分析文档,而是通过一个个 ...

  9. win764位Ruby2.0环境搭建之Ruby on Rails

    一:安装Ruby 1.在http://rubyinstaller.org 下载需要的ruby版本,因为是exe文件,所以,你可以直接安装. 安装结束后,cmd上运行 ruby -v 显示版本号.如果正 ...

随机推荐

  1. Oracle VM VirtualBox 安装 Centos7 并配置静态IP

    新建虚拟电脑 选择类型和版本 设置内存大小 现在创建虚拟硬盘 选择VDI 硬盘足够就选择 固定大小 选择虚拟硬盘存储位置不要放在默认的C盘下,设置大小为30G 等待创建虚拟硬盘 虚拟硬盘创建成果之后 ...

  2. dedecms 调用内容页分页

    arc.archives.class.php $TRUEfilename = $this->GetTruePath().$fileFirst."_".$i.".&q ...

  3. wampserver2.2 在window2003下的安装的主要问题

    准备安装最新的wampserver 2.2c,   1.安装问题,安装完成后总是无法启动服务   系统事件中提示错误 找不到附属汇编 Microsoft.VC90.CRT,上一个错误是 参照的汇编没有 ...

  4. ros 封ip,域名,端口,重定向

    1.封IP / ip firewall filter add chain=forward dst-address=192.168.0.1(想要封的IP) action=drop comment=&qu ...

  5. opengl学习-利用模板测试勾画物体轮廓中出现的一个问题

    我在学习OpenGL模板测试勾画物体轮廓的时候,出现了这个问题: 这个出现的原因就是,改变摄像机的时候,每次绘制,上次绘制中模板缓冲区的数据没有清除的原因.也就是在while循环开始的时候,glCle ...

  6. noi.ac NA534 【猫】

    一眼暴力DP 再一眼决策单调性? 打个表以为是四边形不等式?? 最后发现是斜率优化??? 于是成功写了个假斜率优化真四边形不等式拿了\(80\) 设\(f[i][j]\)表示有\(i\)个工作人员出发 ...

  7. スワコゥのパーフェクトコード教室 ~ Style of suwakow's for OI Codes

    "みんなー! スワコゥのコード教室はじまるよー!" "大家!\(\color{grey}{\text{suwakow}}\)的码风教室开始了哟!" " ...

  8. JAVA》eclipse——(二)Tomcat

    一.进入www.apache.org网页(注:图中所有箭头都依据从左到右,从上到下的规则) 二.向下拉网页,然后如下图操作 三.进入之后,在网页的左边选择想要的Tomcat版本 四.选择与本机相同系统 ...

  9. 一个原生ajax在jetbrains开发平台的调用方法

    这段随笔的记述目的无非是,一个html页面中可能有多段js代码,所以采用外引的方法应该会好一些 function checkfiles() { var xhr = new XMLHttpRequest ...

  10. SparkStreaming HA高可用性

    1.UpdateStateByKey.windows等有状态的操作时,自动进行checkpoint,必须设置checkpoint目录,数据保留一份在容错的文件系统中,一旦内存中的数据丢失,可以从文件系 ...