The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Test::TestCoverage - Test if your test covers all 'public' subroutines of the package

SYNOPSIS

  use Test::TestCoverage;
  
  test_coverage('My::Module');
  
  my $obj = My::Module->new();
  $obj->foo();
  $obj->bar();
  
  # test will be ok, assumed that My::Module has the subroutines new, foo and bar
  ok_test_coverage('My::Module');
  
  reset_test_coverage('My::Module');
  reset_all_test_coverage();
  
  test_coverage('My::Module');
  
  my $obj = My::Method->new();
  $obj->foo();
  
  # test will be not ok, because bar is not invoked
  ok_test_coverage('My::Module');
  
  reset_test_coverage('My::Module');
  reset_all_test_coverage();
  
  test_coverage('My::Module');
  test_coverage_except('My::Module','bar');
  
  my $obj = My::Method->new();
  $obj->foo();
  
  # test will be ok, because bar is excepted of test
  ok_test_coverage('My::Module');

DESCRIPTION

If a module is written, the tests cover just a few subroutines of the module. This module aims to support the author in writing "complete" tests. If one of the "public" subroutines are missed in the testscript, the test ok_test_coverage will fail.

"private" subroutines are defined as subroutines that names begin with _ like _private_sub{...} and "public" is the opposite.

subroutines

test_coverage $module

Tells Test::TestCoverage for what module the coverage should be tested

ok_test_coverage $module

Checks if all "public" subroutines of $module were called in the testscript

reset_test_coverage $module

Resets the counter for all method invokations of $module's subroutines.

reset_all_test_coverage

Resets the counter for all subroutines of all modules that were registerd via test_coverage.

test_coverage_except $module @subs

Test all "public" subroutines of $module except the subroutines named in the array.

all_test_coverage_ok

tests the test coverage for each registered module.

EXPORT

test_coverage, ok_test_coverage, reset_test_coverage, reset_all_test_coverage, test_coverage_except

SEE ALSO

Test::SubCalls, Test::Builder, Test::More, Devel::Cover

BUGS / TODO

There are a lot of things to do. If you experience any problems please contact me. At the moment the subroutines have to be invoked with full qualified names. Exported subroutines are not detected.

AUTHOR

Renee Baecker, <module@renee-baecker.de>

COPYRIGHT AND LICENSE

Copyright (C) 2006 by Renee Baecker

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.