Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Running a set of tests twice

by xdg (Monsignor)
on Dec 09, 2005 at 12:05 UTC ( [id://515516]=note: print w/replies, xml ) Need Help??


in reply to Running a set of tests twice

You might want to look at Test::Class and the section on "Extending Test Classes by Inheritance".

For a more manual approach, what I've often found helpful when I feel like I'm needing identical tests is just creating my testing functions in a helper module that takes an object to be tested (or even just a class name) and a prefix for the test label.

# file: t/helper.pm package t::helper; @EXPORT = qw( run_all_tests ); use strict; use warnings; use base 'Exporter'; use Test::More; sub run_all_tests { my ($obj, $prefix) = @_; diag "Starting tests for $prefix"; isa_ok( $obj, "Parent::Class", "$prefix: object isa Parent::Class" + ); ok( $obj->true(), "$prefix: true() is true" ); # more tests ... } 1;
# file: t/001.t use Test::More 'no_plan'; use t::helper; my @cases = ( Parent::Class->new(), Sub::Class->new(), ); for my $o ( @objs ) { run_all_tests( $o, ref $o ); }

Does that do what you were looking for? Or did you mean something different by "comprehensive output"?

-xdg

Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://515516]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-20 02:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found