BDD:源于TDD而胜于TDD

什么是BDD?
    Behave Driven Development(行为驱动开发?)
为什么要有BDD?
  1.     TDD其实是测试行为的
  2.     TDD的测试用例太专业,业务和需求人员看不懂
  3.     TDD不知道哪些代码需要写测试,怎么写?
  4.     我们要写“规范(specifications)”,所有人都可以读懂,甚至业务人员可以帮你写
  5.     这些“规范”中的每一个都有明确的业务价值
 BDD想要做到开发,需求,测试等人员不光是在开发相同的软件而且要使用同样的语言,什么语言?Specification,我这里翻译为规范。
BDD告诉我们我们要写spec而不是Test,我要做的事是“Specification,not Verification”。
说了这么多,BDD到底什么样子?BDD开发需要一个Behaviour Specification Framework,就像TDD需要xUnit,这里的例子来自RSpec,一个如不要的Behaviour Specification Framework。(I love ruby!)
context  " BDD framework "   do

  setup 
do
    @bdd_framework 
=  BddFramework. new
  end

  specify 
" should be adopted quickly "   do
    @bdd_framework.should_be_adopted_quickly
  end

  specify 
" should be intuitive "   do
    @bdd_framework.should_be_intuitive
  end

end
怎么样?看了有什么感想?
RSpec还有一个rails的插件,可以和rails良好协作,例子代码:
context  " A user (in general) "   do
  setup 
do
    @user 
=  User. new
  end

  specify 
" should be invalid without a username "   do
    @user.email 
=   ' joe@bloggs.com '
    @user.password 
=   ' abcdefg '
    @user.should_not_be_valid
    @user.errors.on(:username).should_equal 
" is required "  
    @user.username 
=   ' someusername '
    @user.should_be_valid
  end

  specify 
" should be invalid without an email "   do
    @user.username 
=   ' joebloggs '
    @user.password 
=   ' abcdefg '
    @user.should_not_be_valid
    @user.errors.on(:email).should_equal 
" is required "  
    @user.email 
=   ' joe@bloggs.com '
    @user.should_be_valid
  end

  specify 
" should be invalid without a password "   do
    @user.email 
=   ' joe@bloggs.com '
    @user.username 
=   ' joebloggs '
    @user.should_not_be_valid
    @user.password 
=   ' abcdefg '
    @user.should_be_valid
  end
end
万恶的csdn来个ruby语法加亮都没有。

参考网址:http://behaviour-driven.org/
http://rspec.rubyforge.org/
http://www.lukeredpath.co.uk/2006/8/29/developing-a-rails-model-using-bdd-and-rspec-part-1
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值