Code Coverage tools help you analyse code to find out which sections are actually called when it is run, and which are not. It is mainly useful for determining test coverage (how much of the code is actually exercised by tests) though it can also be useful in performance analysis.
This little process will help you to get a coverage of your code.
- First you have to get on your
bin path, search for the view script and copy it at view_coverage.
- You need to install the perl coverage module,
- from CPAN; perl -MCPAN -e install Devel::Cover
- in debian: aptitude install libdevel-cover-perl.
- Then add this line at the initial part of view_coverage, just after the GPL message:
use Devel::Cover ('-silent','1','-dir','/var/lib/twiki/pub/coverage/','-select','/.*/');
You can add all the options you like, look at
http://search.cpan.org/~pjcj/Devel-Cover-0.63/lib/Devel/Cover.pm
.
- With this you can access a page with view_coverage/WEB/TOPIC, this will run perl with coverage and generate a cover_db path on /var/lib/twiki/pub/coverage/. On this path are created the files with the coverage information. Take care of the file permissions on the coverage path www-data needs write on it.
- Now you have to go to /var/lib/twiki/pub/coverage/ and run the command cover (it should come with the Cover module.).
- This will generate a visual report on console, and also a few html reports.
Hints and Tips
- Bear in mind that TWiki is complex, and a single run is highly unlikely to exercise more than a small fraction of the code. Be prepared to accumulate coverage results over a number of program runs to get meaningful coverage results.
cover_db can be built incrementally if you give the right options to Devel::Cover.
- You are recommended to write UnitTests so that your coverage results can be duplicated by others and repeated in subsequent TWiki releases.
-
eval can easily defeat Devel::Cover, because it compiles and executes code at runtime. Just because Devel::Cover says an evalled module wasn't covered doesn't mean it wasn't run!
Future Work.
- Automatically create the reports on html, without running the cover command.
- Change the path where the reports are created, a report should be on the same topic path at pub, like
pub/Main/Topic/coverage.html
- Maybe a plugin with this could be extremely useful.
- Derive coverage versions of the unit test suite, to build a true picture of test coverage.
Contributors: MariaDelCarmenHuertas,
CrawfordCurrie