什么是BDD?
Behave Driven Development(行为驱动开发?)
为什么要有BDD?
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
Behave Driven Development(行为驱动开发?)
为什么要有BDD?
- TDD其实是测试行为的
- TDD的测试用例太专业,业务和需求人员看不懂
- TDD不知道哪些代码需要写测试,怎么写?
- 我们要写“规范(specifications)”,所有人都可以读懂,甚至业务人员可以帮你写
- 这些“规范”中的每一个都有明确的业务价值
BDD告诉我们我们要写spec而不是Test,我要做的事是“Specification,not Verification”。
说了这么多,BDD到底什么样子?BDD开发需要一个Behaviour Specification Framework,就像TDD需要xUnit,这里的例子来自RSpec,一个如不要的Behaviour Specification Framework。(I love ruby!)















RSpec还有一个rails的插件,可以和rails良好协作,例子代码:































参考网址: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