[rspec-users] How should I interpret RCov, code coverage?

Sidu Ponnappa ckponnappa at gmail.com
Thu Aug 25 06:12:08 EDT 2011


> Is an RCov code coverage of 100% really good? Because in my opinion a
> method should be tested for more than one case but rcov doesn't care
> about this :(.

RCov is C0 coverage[1]. It's trivial to hit >95% coverage; in fact you
can very quickly achieve >60% coverage by writing a handful of Cukes
on most (simple/new) Rails apps.

> And I've got an unusual good RCov test coverage, 39%(total) and 31%(code
> coverage) - and this with only 12 RSpec examples.
With C0, this isn't unusual. To mitigate this effect, on rails
projects we typically have two coverage report builds - just model
specs, model + controller specs. I typically expect my codebases to
have ~95% coverage for the model build, somewhat higher from the model
+ controller build. I don't usually look at coverage from Cukes as it
doesn't really say very much.

> the methods signatures of that class will count as executed LOC
> 100% tested, therefore the number can grow quite easy. **Right?**
It's not unusual for us to see codebases where the customer mandated a
certain coverage number, but the contractor was unfamiliar with TDD
and so simply wrote specs with no assertions. The coverage numbers are
met, but the specs are useless.

You can mitigate this to some extent with a library like heckle, but YMMV.

> Is there another tool which does a better job on rails projects than
> RCov on test coverage?
AFAIK, Ruby tools only provides C0 coverage metrics.

Best,
Sidu.
http://c42.in

[1] http://grosser.it/2008/04/04/whats-my-coverage-c0-c1-c2-c3-path-coverage/


On 25 August 2011 13:44, Andrei Ursan <lists at ruby-forum.com> wrote:
> First of all I'm new to RCov.
>
> I'm having a rails application with around 20 models and 20 controllers
> + helpers and others.
>
> And I've got an unusual good RCov test coverage, 39%(total) and 31%(code
> coverage) - and this with only 12 RSpec examples.
>
> I'm running RCov with the following options:
>
>  t.rcov_opts  = "--callsites --xrefs  --no-comments --rails --exclude
> test/*,spec/*,features/*,factories/*,gems/*"
>
> What kind of heuristic is RCov using? I'm reading its manual
> http://www.linuxcertif.com/man/1/rcov/ and it says:
>
>> rcov is a code coverage tool for Ruby. It creates code coverage
>> reports showing the unit test coverage of the target code.
>>
>> rcov does "statement coverage", also referred to as "C0 coverage analysis". It
>> tests, if each line of the source code has been executed.
>>
>> rcov is typically used to find the areas of a program that have not
>> been sufficiently tested. It reports, what code has not been run by
>> any test cases.
>
> That being said, it means that:
>
> (in my case) 31%  Lines Of Code of the application logic have been
> executed by the test files. E.g. if a method has been executed for one
> test case than that method (the LOC that represent that method) are 100%
> tested. The bad side is that if a test file loads a Class A (just by
> including its name into its logic), and doesn't execute any of its
> method, the methods signatures of that class will count as executed LOC
> 100% tested, therefore the number can grow quite easy. **Right?**
>
>
> Is an RCov code coverage of 100% really good? Because in my opinion a
> method should be tested for more than one case but rcov doesn't care
> about this :(.
>
> Is there another tool which does a better job on rails projects than
> RCov on test coverage?
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list