Rspec vs. TestUnit

前端 未结 6 1486
盖世英雄少女心
盖世英雄少女心 2020-12-23 20:14

I\'m beginning the planning phase of creating a testing suite for my rails 3.0.8 application. I\'m trying to decide on which testing framework/gems to use. Normally I prefer

相关标签:
6条回答
  • 2020-12-23 20:15

    If you're beginning your journey with testing Rails application I would recommend you start doing it with TestUnit. You can find very nice course about best testing rails app and best practices on http://www.codeschool.com/courses/rails-testing-for-zombies If you're more experienced when it comes to testing you can try RSpec.

    0 讨论(0)
  • 2020-12-23 20:16

    This Ruby Inside article, especially if you follow the links and read the comments, provides quite a thorough discussion of the relative merits of Test::Unit and RSpec. A key differentiator seems to be that:

    • people who have non-technical clients are more likely to view RSpec and Cucumber more favourably;
    • others are more likely to prefer more direct systems like Test::Unit.

    Also see this part of Michael Hartl's Rails Tutorial for a comparison of RSpec and Cucumber.

    0 讨论(0)
  • 2020-12-23 20:20

    You could use rspec with cucumber and webrat gems which makes a great combination, if you have a large website. It will be cumbersome at first but later on it will be a huge benefit.

    You could watch the following railscasts episodes to have more info about those gems:
    155 Beginning with Cucumber
    156 Webrat
    157 RSpec Matchers & Macros
    159 More on Cucumber

    There are also some other gems like capybara which is relatively new and promising, but honestly I didnt try it.

    0 讨论(0)
  • 2020-12-23 20:27

    Both Test::Unit and Rspec are very nice solutions. As for me I prefer to use RSpec in my Rails project - because it has many automatic solutions like autotest, highlighting syntax, shortcut commands like rake spec and other stuff that make using test easer. But in my plain ruby scripts I use Test::Unit - it is very lightweight and staightforward when you don't need complex testing (integrational and others)

    0 讨论(0)
  • 2020-12-23 20:28

    The answer is matter of taste, use both in one project and find yourself what do you prefer. (I do Test::Unit, RSpec has to much sugar for me).

    Update 2014: As Ruby 2.x has MiniTest built-in I would suggest to check MiniTest::Spec eventually which is simple BDD extension. You can mix "describe" and "it" blocks to nicely structure test contexts with. It also provides "must_be.." matchers if you want to more than assert.

    0 讨论(0)
  • 2020-12-23 20:30

    I prefer and use these gems for testing

    • Rspec
    • Faker (for creating random and proper data for database)
    • Fabrication (for simple creating instances)

    To start with rspec take a look at this presentation. It contains all the necessary examples:

    http://kerryb.github.com/iprug-rspec-presentation

    Also read through these articles on rspec:

    http://relishapp.com/rspec/rspec-rails

    0 讨论(0)
提交回复
热议问题