Skip to Main Content
Professional Ruby on Rails™
book

Professional Ruby on Rails™

by Noel Rappin
February 2008
Intermediate to advanced content levelIntermediate to advanced
479 pages
14h
English
Wrox
Content preview from Professional Ruby on Rails™

7.2. Covering It All

When you're trying to determine the quality of a set of unit tests, the most basic question you need to ask yourself is whether the tests actually fully exercise the code being tested — a metric known as code coverage. Code coverage is the simple percentage of the application code that is executed when the test suite is run. Coverage can be computed based on the number of lines in the code or by the number of branch paths through the code. Although you could get in a nice programmer-minutia kind of argument over which is the One True Way of measuring coverage, the fact is that in your Rails applications, the goal is complete 100-percent coverage. (Actually, I've started to shoot for 100 percent two ways: 100-percent coverage of the models from the unit tests alone, and 100 percent for the application as a whole from the entire test suite.) The details of the measuring metric are not really that important.

Obviously, coverage in and of itself does not guarantee test quality — for instance, the tests might cover everything but never have any assertions, which only verifies that the program runs without crashing (and in fairness, there are times when that's a perfectly valid test). Lack of coverage pretty much ensures that the test suite is in some trouble — the parts of your application that are missing tests often contain problem code. However, if you are confident that your test writers can consistently and competently create tests that are actually doing ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Ruby on Rails® Bible

Ruby on Rails® Bible

Timothy Fisher
Rails 4 in Action

Rails 4 in Action

Yehuda Katz, Rebecca Skinner, Stephen Klabnik, Ryan Bigg

Publisher Resources

ISBN: 9780470223888Purchase book