`
kuwoleft
  • 浏览: 1068165 次
文章分类
社区版块
存档分类
最新评论

用Cucumber脚本做故事驱动开发

 
阅读更多

原文:

http://www.infoq.com/cn/news/2009/03/bdd-with-cucumber


行为驱动开发(BDD)的流行已然无可逆转。它始创于2003年,由Dan North创立,与测试驱动开发相呼应。BDD鼓励软件项目中的各种角色相互协作:开发人员、QA、非技术角色或者业务分析师。

Ruby因其便于创建和使用DSL的特性,也带来了许多BDD框架的诞生,如RSpecAslak Hellesøy的作品Cucumber也是其中一例,它可以用来测试Java、.NET和Flex代码。也可以读取纯文本文件,执行自动化功能测试。

下面是一个典型的场景示例(来自于项目的Wiki):

Feature: Search courses
  In order to ensure better utilization of courses
  Potential students should be able to search for courses

  Scenario: Search by topic
    Given there are 240 courses where neither has the topic "biology" 
    And there are 3 courses A,B,C that each have "biology" as one of the topics
    When I search for "biology" 
    Then I should see a the following courses:
      | title |
      | A     |
      | B     |
      | C     |

然后就可以用真实的代码来实现这段话,在测试失败中不断迭代直至最后成功。Cucumber还支持把场景中失败或者成功的部分加以高亮显示(下面是Cucumber网站上的一张图片):

Tests failure

编写Cucumber文件的语言是Gherkin,它可以附着于各种自然语言之上,它的关键字就是“Given”、“And”等等这样的字眼,另外还可以用法语、德语等等语言来写。用户编写好每一步的定义以后,Cucumber就会一步一步的解析关键字右侧的自然语言并执行代码。

应用Cucumber的方式有很多,例如给系统管理员用作Web应用的集成测试,或者将分布式系统集成并测试消息机制,又或者编写PDF的测试

Cucumber的0.1.16版本可以做为Ruby Gem下载,0.1.99.10版本可以在GitHub上获取。

查看英文原文Story Driven Development Recipes with Cucumber

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics