COMP 402: Production Programming← Code Coverage Tools → |
Home — Spring 2012 | | | Information | | | Resources | | | DrJava | | | SourceForge | | | Blog |
Code coverage tools record what parts of the program are executed. This is particularly useful in conjunction with unit tests, since the results of those tools show which portions of the program are exercised by the tests. For example, it can tell you that a test with an if-then-else
construct only enters the then
block, but never the else
block.
To remember what lines have been executed how many times, either the source code or the compiled class files are annotated with counters for each line of code and statements incrementing those counters. Then the tests are run as usual, with the side effect of remembering how may times a line was executed. Before the program finishes, the values of the counters are written to disk and a report is generated.
As long as you have Clover available on your system (e.g. on CSnet), you can run the unit tests and generate a code coverage report by typing:
ant clover
We will try to keep updated test coverage reports on the DrJava website.
URL: http://www.cs.rice.edu/~javaplt/402/12-spring/lectures/codeCoverage/index.shtml