Cucumber是一个能够理解用普通语言描述的测试用例的支持行为驱动开发(BDD)的自动化测试工具,用Ruby编写,支持Java和.Net等多种开发语言。
Cucumber 三大组成:
- Features
- Step_definitions
- Cucumber command
Feature是用简单的自然语言描述的。一个Feature有下面部分组成:
- 一个title
- 一段任意格式的描述语句
- 任意数目的scenarios
- 每个scenario可以包含任意数目的steps
- Step定义必须以关键字Given, When, Then, And 开始
- Feature文件必须以.feature为后缀名
Step_definitions根据feature文件中定义的step编写对应的测试代码,所用编程语言可以和所测应用程序编程语言一致。
Cucumber command, 当运行cucumber命令时,cucumber会分析feature文件中定义的step,然后去step_definitions寻找相匹配的step,如果找到就执行step中的代码。 执行命令,在命令行中输入cucumber项目目录features文件名.feature
Cucumber 的开发过程(摘自http://cukes.info/):
1: Describe behaviour in plain text

2: Write a step definition in Ruby

3: Run and watch it fail

4. Write code to make the step pass

5. Run again and see the step pass

6. Repeat 2-5 until green like a cuke
