Cucumber —— 优雅、跨语言的 BDD 框架

783 查看

cucumber 是 一个优雅的BDD(行为驱动开发)方案。

示例

Feature: Search courses
  Courses should be searchable by topic
  Search results should provide the course code

  Scenario: Search by topic
    Given there are 240 courses which do not have the topic "biology"
    And there are 2 courses A001, B205 that each have "biology" as one of the topics
    When I search for "biology"
    Then I should see the following courses:
      | Course code |
      | A001        |
      | B205        |

方法

1. 使用简明的语言定义行为

2. 改写成 Ruby

3. 运行(等着看它失败)

4. 编写代码,使得测试可以通过

5. 再次运行(这次应该看到有测试通过了)

3 6. 重复 2-5,直到所有测试通过

安装

确保你已经安装了 Ruby,然后使用 gem 安装;

gem install cucumber

运行 cucumber --help 查看帮助。

Cucumber 使用 Ruby 编写,但是它不仅适用于 Ruby,还适用于其他语言:

此外,Cucumber 还支持大量的测试工具和网站框架,详情见此

学习资源

项目主页

http://cukes.info/


编撰 SegmentFault