英文语法:
# language: en
Feature: Addition
In order to avoid silly mistakes
As a math idiot
I want to be told the sum of two numbers
Scenario: case 1 - Add two numbers
Given the input "2+2"
When the calculator is run
Then the output should be "4"
Scenario Outline: case 2 - Add two numbers
Given the input "<input>"
When the calculator is run
Then the output should be "<output>"
Examples:
| input | output |
| 2+2 | 4 |
| 98+1 | 99 |
*But也是常用的关键字
*Given,When,Then,But都可以在一个Scenario里出现一次或者不出现
*Given后的And等同于Given, Then后的And等同于Then
中文语法:
# language: zh-CN
功能:加法
为了避免一些愚蠢的错误
作为一个数学白痴
我希望有人告诉我数字相加的结果
场景: 两个数相加
假如我已经在计算器里输入6#Given
而且我已经在计算器里输入7#And(Given)
当我按下相加按钮#When
那么我应该在屏幕上看到的结果是13#Then
场景大纲: 将两个数相加
假如我已经在计算器上输入<数值_1>
而且我已经在计算器上输入<数值_2>
当我按下 <按钮>
那么我应该在屏幕上看到<结果>
例子:
| 数值_1 | 数值_2 | 按钮 | 结果 |
| 20 | 30 | add | 50 |
| 2 | 5 | add | 7 |
| 0 | 40 | add | 40 |
常用关键字
Feature(功能)
Scenario(情景)
Given(给定)
And(和)
When(当)
Then(则)
Feature (功能)
test suite (
测试用例集)
Scenario(情景)test case (测试用例)
Given(给定)setup(创建测试所需环境)
When(当)test(触发被测事件)
Then(则)assert(断言,验证结果)
格式化工具:官网说notepad++有支持feature文件的高亮插件。但没找到,所以自己定义了一组gherkin语言规则。