Introduce Cucumber(Automation Testing)

测试只能证明程序有错误, 不能证明程序没有错误.

1. What is Cucumber?

Cucumber is a software tool that supports behavior-driven development. It allows expected software behaviors to be specified in a logical language that customers can understand. The specifications consists of multiple examples, or scenarios. For example:

or

or

Each scenario(story) 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.

2. 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(or story) 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.

3. Gherkin Keywords

Each line that isn’t a blank line has to start with a Gherkin keyword, followed by any text you like. The only exceptions are the feature and scenario descriptions.

The primary keywords are:

  • Feature

  • Scenario

  • GivenWhenThenAndBut for steps (or *)

  • Background

  • Scenario Outline (or Scenario Template)

There are a few secondary keywords as well:

  • """ (Doc Strings)

  • | (Data Tables)

  • @ (Tags)

  • # (Comments)

4. Automated testing using Cucumber

  • We write Java source code to implement the scenario.

  • We run test scenarios by Cucumber class.

  • Scenario: Get Cucumber report

    • Given we run some test scenarios

    • When completed

    • Then we can get a Cucumber report

Of course, the blog is only a small part of Cucumber knowledge, and if you want, you can learn and discover a lot of interesting things from Cucumber.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值