You are on page 1of 7

Pragmaticraft

Writing better code using the RCov code coverage tool


github.com/igal/rcov_tutorial

Igal Koshevoy, Pragmaticraft Business-Technology Consultant igal@pragmaticraft.com @igalko on Twitter I!enti.ca

"RCov tutorial" for pdxruby - Igal Koshevoy - 2010-02-02

Pragmaticraft

Terminology

rcov: " co!e coverage tool for #u$y Code coverage report: %escri$es what co!e is e&ecute! '(covere!() $y tests*specs. X% coverage : Percentage of your co!e covere! $y tests*specs + more is $etter.

"RCov tutorial" for pdxruby - Igal Koshevoy - 2010-02-02

Pragmaticraft

Why should you care'

Co!e coverage can help you fin! $ugs an! missing test cases. ,seful for!. "#isting code base: fi& an! sta$ili.e that $ug-ri!!en mess $. %e& commits: catch $ugs in the most likely place + new co!e without coverage

"RCov tutorial" for pdxruby - Igal Koshevoy - 2010-02-02

Pragmaticraft

Caveats

It/s a tool, not a silver $ullet 0112 co!e coverage is usually impossi$le 3ocks an! stu$s help cover more co!e, $ut prevent e&ecution from reaching the stu$$e! calls an! mocke! classes %iminishing returns set in somewhere $etween 12 an! 0112 co!e coverage -% #Cov !oes line coverage, not path coverage444 '%iscusse! later)
"RCov tutorial" for pdxruby - Igal Koshevoy - 2010-02-02

Pragmaticraft

(ample code
5ource- githu$.com*igal*rcov6tutorial The 7myli$rary8 !irectory contains

9i$rary that/s $eing teste!*spec/e! 5pec file that !escri$es li$rary/s $ehavior #akefile to generate coverage reports for

7 ra)e *T 8 for instructions 7 ra)e rcov 8 to create report for all co!e 7 ra)e rcov:save 8 an! 7 ra)e rcov:di++ 8 save state an! report new uncovere! co!e
"RCov tutorial" for pdxruby - Igal Koshevoy - 2010-02-02

Pragmaticraft

RCov does line coverage, not path coverage--This succinct line is always shown as covere! + it !oesn/t tell you if 0*1 was runputs 0*1 unless lucky: #ewriting this as separate lines makes it o$vious that 0*1 wasn/t runif lucky: puts 0*1 en!
"RCov tutorial" for pdxruby - Igal Koshevoy - 2010-02-02

Pragmaticraft

. /0 RCov

;asy an! useful way to write $etter co!e <in!s $ugs you forgot to !eal with <in!s tests you forgot to write <in!s pro$lems in co!e people su$mitte! 5urprising useful even at high co!e coverage levels

"RCov tutorial" for pdxruby - Igal Koshevoy - 2010-02-02

You might also like