Cucumber Introduction

https://cucumber.io/docs/guides/overview/

Cucumber is a tool that supports Behaviour-Driven Development(BDD). If you’re new to Behaviour-Driven Development read our BDD introduction first.

What is Cucumber?

Ok, now that you know that BDD is about discovery, collaboration and examples (and not testing), let’s take a look at Cucumber.

Cucumber reads executable specifications written in plain text and validates that the software does what those specifications say. The specifications consists of multiple examples, or scenarios. For example:

Scenario: Breaker guesses a word
  Given the Maker has chosen a word
  When the Breaker makes a guess
  Then the Maker is asked to score

Each scenario is a list of steps for Cucumber to work through. Cucumber verifies that the software conforms with the specification and generates a report indicating ✅ success or ❌ failure for each scenario.

In order for Cucumber to understand the scenarios, they must follow some basic syntax rules, called Gherkin.

What is Gherkin?

Gherkin is a set of grammar rules that makes plain text structured enough for Cucumber to understand. The scenario above is written in Gherkin.

Gherkin serves multiple purposes:

  • Unambiguous executable specification
  • Automated testing using Cucumber
  • Document how the system actually behaves

 

 

The Cucumber grammar exists in different flavours for many spoken languages so that your team can use the keywords in your own language.

Gherkin documents are stored in .feature text files and are typically versioned in source control alongside the software.

See the Gherkin reference for more details.

 

What are Step Definitions?

Step definitions connect Gherkin steps to programming code. A step definition carries out the action that should be performed by the step. So step definitions hard-wire the specification to the implementation.

┌────────────┐                 ┌──────────────┐                 ┌───────────┐
│   Steps    │                 │     Step     │                 │           │
│ in Gherkin ├──matched with──>│ Definitions  ├───manipulates──>System   │
│            │                 │              │                 │           │
└────────────┘                 └──────────────┘                 └───────────┘

Step definitions can be written in many programming languages. Here is an example using JavaScript:

When("{maker} starts a game", function(maker) {
  maker.startGameWithWord({ word: "whale" })
})

 

作者:Chuck Lu    GitHub    
posted @   ChuckLu  阅读(58)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2020-05-25 xml security issue
2020-05-25 Non-scalar subquery in place of a scalar
2019-05-25 域名信息备案查询 以及 国家企业信用信息公示
2019-05-25 404. Sum of Left Leaves
2019-05-25 git修改commiter date
2017-05-25 Exception: Operation xx of contract xx specifies multiple request body parameters to be serialized without any wrapper elements.
2017-05-25 如何测试WCF Rest
点击右上角即可分享
微信分享提示