开发者

TDD? BDD? I'm confused! What should I use for testing and why?

So yeah, I'm gettin' into this testing thing!

But 开发者_运维百科I don't know what to use =/

Rspec + Shoulda?

Rspec + Steak?

Minitest?

Cucumber?

Capybara?

Coulda? (Cucumber with Shoulda mixup)

Mini_shoulda? (Minitest with Shoulda mixup)

Argh, so many choices! I'm confused <.< I do know I want something small and simple to test my future gems and sinatra & rails apps. What do you people use and why?


If you are just starting out, you should go with the defaults and follow the official guides. The important thing is that you practice testing. It's less important which testing library/framework you use - that's a stylistic choice that's secondary to actually practicing testing in the first place - and the easiest way to get starting testing your Rails app is to follow the "Golden Path" that the official guides lay out.

Once you get more comfortable with testing your Rails app, you will be in a much better position to evaluate the options out there. I personally like rspec and cucumber (at the moment - I may decide to change my preference), but I was only able to come up with this preference after already being somewhat familiar with testing and after already being somewhat familiar with Rails.


I just came across this blog post which states:

It seems that the accepted way to test in Ruby is to use Rspec for unit tests and to use Cucumber for acceptance tests (higher level functional testing).

It then goes on to ask: "if we agree that BDD is good, why don’t we write our unit tests in a format that is more amenable to BDD, that being the Cucumber format of tests?" and compares rspec unit tests against unit tests in Cucumber.


At work we use the pretty standard RSpec and Cucumber combination. I don't know how they decided on this specific combination, it was already there when I started and worked for us, so there was no need to change. Also it's a quite widely use combination so finding examples with Google etc. isn't too hard.

For my 1.9 based private projects I think I will use Minitest from now on. No external dependencies, a simple BDD DSL (require 'minitest/spec') and some other niceties like randomization. Here's a nice quick intro:

http://www.bootspring.com/2010/09/22/minitest-rubys-test-framework/


For someone just getting started I recommend just using RSpec. It doesn't do everything but it will allow you to build up reasonable sets of unit and integration tests. When you run into the limits of what RSpec handles easily then let that need guide you in choosing additional tools.


Can't offer anything more sensible than Justice, but before you ignore that wisdom :-) do check out this video (minitest author Ryan Davis at Cascadia 2011 ruby conf):

http://confreaks.net/videos/618-cascadiaruby2011-size-doesn-t-matter

slides: http://www.zenspider.com/~ryan/presentations/CascadiaRubyConf_2011_-_Size_Doesn%27t_Matter.pdf

Being able to run all your tests very quickly is a very good thing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜