# Cucumber Getting Started Notes (BDD Automated Testing Framework)
tags:`publishmynoteblog`

## TOC
* [Cucumber Getting Started Notes (BDD Automated Testing Framework)](https://hackmd.io/@onejar99/BJ9LkkBNH#Cucumber-%E5%85%A5%E9%96%80%E7%AD%86%E8%A8%98-BDD%E8%87%AA%E5%8B%95%E5%8C%96%E6%B8%AC%E8%A9%A6%E6%A1%86%E6%9E%B6)
* [TOC](https://hackmd.io/@onejar99/BJ9LkkBNH#TOC)
* [Concept introduction](https://hackmd.io/@onejar99/BJ9LkkBNH#%E8%A7%80%E5%BF%B5%E4%BB%8B%E7%B4%B9)
* [BDD](https://hackmd.io/@onejar99/BJ9LkkBNH#BDD)
* [Cucumber](https://hackmd.io/@onejar99/BJ9LkkBNH#Cucumber)
* [Gherkin description syntax (feature)](https://hackmd.io/@onejar99/BJ9LkkBNH#Gherkin-%E6%8F%8F%E8%BF%B0%E8%AA%9E%E6%B3%95-feature)
* [Step Definitions](https://hackmd.io/@onejar99/BJ9LkkBNH#Step-Definitions)
* [Step Keywords](https://hackmd.io/@onejar99/BJ9LkkBNH#Step-Keywords)
* [References](https://hackmd.io/@onejar99/BJ9LkkBNH#References)
*
## Concept introduction
### BDD
* BDD (Behaviour-Driven Development) is used to identify problems, facilitate collaboration and demonstration, rather than testing itself.
> BDD is about discovery, collaboration and examples (and not testing).
> (Ref: Cucumber: Introduction )
* Why BDD?
TDD is a software development process that tests first and then develops
The test code implemented by TDD can serve as the basis for discussions between engineers on test cases or usage scenarios.
However, for non-developers, such as PM, PO, and Designer, it is difficult to understand the test cases they want to discuss through the program code, and it is also more difficult to further discuss the functions of the software based on the test cases.
* What's BDD?
TDD means writing tests before implementation
BDD goes one step further than TDD. Before writing tests, you must first write test specifications. This test specification will describe software functions and test cases in a way that is closer to human semantics.
However, this specification is not simply a description of the function of the software, but a "specification that can be executed", that is, it can be converted into [automated testing](https://testsigma.com/automated-testing).
### Cucumber
* Cucumber is a tool that supports BDD.
* You can read plain text specification files and verify whether the software conforms to the Spec description.
* Important terms: specification, scenario, step
* A specification contains multiple scenarios, and each scenario has many steps to complete.
* (In Cucumber, an example is called a scenario).
A specification is executable and is described using a syntax called Gherkin.
* Cucumber verifies that software complies with specifications and generates a report indicating the success or failure of each scenario.
* Write Scenarios/specification first before writing Production code).
* When the Production code is written, Scenarios serve as living documentation and automated testing.
* Cucumber's three major purposes:

(Source: [Cucumber: Introduction](https://cucumber.io/docs/guides/overview/) )
### Gherkin description syntax (feature)
* A simple description syntax for writing specifications.
* Gherkin serves several purposes:
* It can describe clear and executable specifications so that Cucumber can understand them and has human semantic readability.
* Can perform automated testing through Cucumber
* Able to document the actual behavior of the system (actually behaves)
* Gherkin's writing supports many human languages, and the team can use the language they like
* eg, English, Traditional and Simplified Chinese
* Ref: Cucumber: [Gherkin Reference - Spoken Languages](https://cucumber.io/docs/gherkin/reference/#spoken-languages)

(Source: [Cucumber-java Getting Started Basics - chengly0129's column - CSDN blog](https://blog.csdn.net/chengly0129/article/details/79197598) )
* Gherkin files
* Scenario written in Gherkin representation
* Save `.featurethe` file with the file extension and place it `feature`under or its subfolder.
* A project has many features, one `.feature`file has many scenarios, and one scenario has many steps.
* Gherkin files will be added to version control together
* Who should write Gherkin
* It is recommended to be a developer or tester
* PO or business writing is easily counterproductive (maybe after all, engineers don’t have the concept of grammatical definition like engineers do)
### Step Definitions
* In order to convert the steps in the specification into an implementation programming language (eg, JavaScript, Java)
* Step Definitions define each Gherkin Stepcorresponding implementation (called a hard link hard-wire)
* Who should write Step Definition:
* The same people who wrote Gherkin
* This is why it is recommended that Gherkin be written by a developer or tester
### Step Keywords
Ref: Cucumber: Gherkin Reference - Steps
In the feature file, each Gherkin Stepitem will be preceded by a keyword, for example Given,When
* Keywords starting with Step:
* 1. Note: When Cucumber looks for Gherkin Stepcorresponding step definitions, it doesn't care what the keywords are.
* 1. In other words, you cannot use two Keywords to define step definition in the same sentence grammar.
* 1. For example, the following will be considered a duplicate definition:
* 1. Given I log in
* 1. Then I log in
* 1. In other words, what keywords are used for a step does not actually affect the program, but choosing keywords with appropriate semantics is more conducive to human reading.
* 1. What the actual step does depends on the implementation content of Step Definitions.
* If you insist, you can also implement the action of the Then concept in the step at the beginning of Given.
## References
[Cucumber official website](https://cucumber.io/)
[Cucumber: Guides (Official Tutorial)](https://cucumber.io/docs/guides/)
[Chapter 1 - Summary of Automated Testing Framework Cucumber - IT Reading - ITREAD01.COM](https://www.itread01.com/content/1544337666.html)
[Basics of getting started with Cucumber-java - chengly0129's column - CSDN blog](https://blog.csdn.net/chengly0129/article/details/79197598)