O'Reilly logo

Professional Ruby on Rails™ by Noel Rappin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required