Large-scale unit testing practices in Rails
What are some general guidelines, procedures, or practices for testing large, complicated Rails applications? Are there certain pieces of an application(ie. user auth, search) that should be tested over others? When and how should tests be run in an ongoing development cycle?
I'm fairly new to Rails and large-scale development in general, but I have a decent grasp of the Rails framework through online guides and personal tinkering. I don't, however, know how to approach the task of testing an app that's already in development, with many models and controllers. My ultimate goal is to develop a testing harness for this application, but for now I'm trying to learn how Rails developers go about testing their (big) applications. Any reso开发者_Go百科urces or advice on related topics is greatly appreciated.
Every line below is debatable; this is just what works for me:
- Let your unit tests be true unit tests, not functional tests. Isolate them with mocks and stubs, they make tests easier to write, read and change.
- To give yourself the freedom to do true unit tests, supplement them with integration tests. At least visit each of your routes and check the response code.
- The debugger gives you wings.
- FactoryGirl, or something else that isn't fixtures.
- Rcov / SimpleCov. Train yourself to feel naked when uncovered.
- Rspec, Shoulda, Webrat. Take the time to make your specs scan in English. Read the book. Write lots of spec helpers and custom matchers.
- Ixnay on Cucumber, too verbose, adds little.
- Jenkins. Integrate with a coverage tool & flog. Never deploy without a green light.
精彩评论