Database Reference
In-Depth Information
Generating Code Coverage Metrics
These days, it's not enough to write good unit tests: you also need to prove that you're
covering all the code with them. As previously mentioned, you can use the gcov library
to produce code coverage results from your unit tests. To do this, turn on the Generate
Test Coverage Files flag in the Build Settings of your unit test target, as shown in
Figure 5-4 .
Figure 5-4. Turning on code coverage in XCode
Once you've turned on code coverage support and run your unit tests, you're going to
end up with a bunch of files with gcda and gcno extensions somewhere. Perhaps in
your project directory; more likely in some place like ~/Library/Developer/Xcode/De-
rivedData . Unfortunately, these files are next to useless to try and interpret visually.
Fortunately, there are good tools such as CoverStory to do all the hard work for you.
CoverStory is available at http://code.google.com/p/coverstory/ , and is a normal Mac OS
X application. When you run it, you can use the File Open command to point it at a
directory (or tree of directories) containing your code coverage files. It then opens up
and displays a listing of your code, with unrun code shown in red, and counts next to
each line showing how many times each line ran ( Figure 5-5 ).
CoverStory also gives you a list of files on the left-hand side, along with code coverage
percentages, so you can see how your code is doing, coverage-wise, and find under-
covered files.
 
Search WWH ::




Custom Search