0

I just implemented an excellent example of test coverage in Perl described at Perl, Code Coverage Example

But that required Module::Build , Now what if i have existing Perl Application which does NOT have the Module::Build instrumentation, is there a way to get test coverage for unit or functional tests ?

I looked at :

Clean up from previous test run (optional)
  cover -delete

  #Test run with coverage instrumentation
  PERL5OPT=-MDevel::Cover prove -r t

  #Collect covered and caller information
  #  Run this _before_ running "cover"
  #  Don't run with Devel::Cover enabled
  covered runs
    - or e.g. -
  covered runs --rex_skip_test_file='/your-prove-file.pl$/' \
          --rex_skip_source_file='{app_cpan_deps/}'

  #Post process to generate covered database
  cover -report Html_basic


  %perl -d:Coverage -Iblib/lib test.pl

But this seems to indicate Code Coverage while running the application.

I want to be able to get a Clover or Cobertura Compatible output, so i can integrate it with email-ext in Jenkins

Community
  • 1
  • 1
kamal
  • 9,637
  • 30
  • 101
  • 168

1 Answers1

3

Task::Jenkins may be of some help. It has instructions about how to publish the Devel::Cover HTML reports through Jenkins, as well as info about adapting other Perl tools to Jenkins.

Jira has some instructions about integrating Devel::Cover into Jenkins.

To get code coverage for any Perl process (test, application, server, whatever) you set the PERL5OPT environment variable to -MDevel::Cover which is like putting use Devel::Cover in the program. If your command to execute tests is perl something_test then you'd run PERL5OPT=-MDevel::Cover perl something_test.

If you're using prove, use HARNESS_PERL_SWITCHES=-MDevel::Cover prove <normal prove arguments>. This tells prove to load Devel::Cover when running the tests, but avoids gathering coverage for prove itself.

Denis Ibaev
  • 2,470
  • 23
  • 29
Schwern
  • 153,029
  • 25
  • 195
  • 336
  • does that mean PERL5OPT=-MDevel::Cover prove --timer --formatter=TAP::Formatter::JUnit -v -r . > perlapp_smoke.xml 2>perlapp_smoke.err would NOT work ? Since it does not have perl something_test format, but rather has prove. – kamal Mar 17 '13 at 04:19
  • Thanks, How to get the HTML report while running with prove? – Srikanth Jeeva Jul 18 '17 at 22:03
  • Figured out. `cover -test` generated the HTMLs. Thanks! – Srikanth Jeeva Jul 19 '17 at 19:41