What testing frameworks are used for Rails? [close

2020-07-09 07:11发布

What unit testing frameworks are used for Rails?

I am reading the book (Pragmatic Programmers Agile Dev. with Rails) which shows how to do unit tests in Rails.

The book showed me the default rails testing suite (a subclass of Test::Unit). Is this the main testing framework that is used in the Rails community? I use RSpec when doing regular ruby, and I would like to be able to use it in Rails too (if it's not too much of a hassle)?

5条回答
爱情/是我丢掉的垃圾
2楼-- · 2020-07-09 07:51

I would say rspec is the most widely used. It's easy to get it up and running, it's expressive and easy to use. Rails comes with Test::Unit support by default, but I don't see many people using it. And of course there's a myriad of smaller testing frameworks that a small number of people use. But it's mostly rspec.

查看更多
成全新的幸福
3楼-- · 2020-07-09 07:56

There are many tools for testing rails and other webapps from many different aspects. But if you are new to testing I highly recommend you start with learning Rails' own testing framework before start using other tools.

Learning, and later mastering, one testing framework makes it easier in the future to understand pros/cons with other framework and make them work in unison.

You could start with testing the following things:

  • Unit Testing your Models
  • Functional Tests for Your Controllers
  • Learning about Fixtures and how to load test data

I have seen many failed testing efforts, but I never saw them fail because they choose the wrong tool/framework. They fail because they don't know how to master the tools they use, and learn enough about the basics about testing.

Read more about Rails testing here.
http://guides.rubyonrails.org/testing.html

查看更多
小情绪 Triste *
4楼-- · 2020-07-09 07:57

Yes, rspec is used for Rails too. You can find some other examples listed here (although I didn't try most of them).

查看更多
Summer. ? 凉城
5楼-- · 2020-07-09 07:59

Rspec is widely used in rails, and in conjunction with Cucumber, is one of the most widely used solutions today. note that rails 3 is using rspec 2, so look for rspec/rails. check out the pragprog.com book rspec and cucumber, a great resource written by the core teams. http://pragprog.com/titles/achbd/the-rspec-book

查看更多
登录 后发表回答