9th Nov, 2007

在test:unit中应用BDD

techno-weenie.net提供了两个插件simple_bdd和test_spec_on_rails,可以让你在test:unit中应用BDD而不需安装rspec,如果再加上mocha,test:unit与rspec就只存在语法的差异了。

安装:

script/plugin install http://svn.techno-weenie.net/projects/plugins/simply_bdd/
script/plugin install http://svn.techno-weenie.net/projects/plugins/test_spec_on_rails/

使用:

1. simple_bdd:

context "New User" do
  def setup
  end
  specify "should be invalid without a username" do
  end
end

这相当于:

class NewUserTest < Test::Unit::TestCase
  def setup
  end
  def test_should_be_invalid_without_a_username
  end
end

test_spec_on_rails:

#model
@user.should.validate
@user.should.be.validated
#Redirection
response.should.be.redirected # assert_response :redirect
response.should.redirect foo_url(@foo) # assert_redirected_to foo_url(@foo)
should.redirect_to :action => 'show' # because "response" is optional

更多请参看README.

另外DUST也提供和simple_bdd类似的功能。

评论

I personally like ‘shoulda’, very simple and easy to use. http://thoughtbot.com/projects/shoulda

shoulda是不错,不过它是一个全新的测试框架,比较庞大

感觉这个也没有多大的作用,能用rspec的地方,就直接用Rspec了,有时候分布式开发,照顾别的程序员,不会用rspec,只会写unit test,用了这个插件语法上也有差异,还不如直接去用rspec。
个人意见。

留条评论?

Your response:

Categories