silkybones has asked for the wisdom of the Perl Monks concerning the following question:
Greetings Monks. Long time listener. First time caller.
Basically, I'm using Test::More to deal with Unit-testing a huge and unruly codebase, but I want to be able abstract out common Test::More assertion wrappers so I can re-use them.
I've looked at TAP::Harness, Test::Builder, and other modules. The only one that seems to get close to what I need is Test::Builder (which is not based on Test::More) because you can actually call new(), or create() on the class, and then set the number of tests, and tell the class when to run tests.
Basically, the client of the Test::More extension/wrapper class would do things like this:
use MyTestMoreRunner; my $testMoreWrapper = MyTestMoreWrapper->new( # the runner will set Test::More's test => 20 numTests => 20, # the class I'm testing testClass => 'theClassImTesting', ); $testMoreWrapper->runTest( # test name (Test::More assertion's 3rd arg testName => "testSomething returns 20", # these get passed to theClassImTesting params => { foo => 'foo', bar => 'bar' }, # assertions on what theClassImTesting returns is => 20 ); $testMoreWrapper->done();
The point of this is that I'd like my test classes to not have to use Test::More. I want my test classes to to able to share functions that wrap Test::More assertions, so I don't have to do things like this in each of my test classes:
sub okExplain { my ($result, $desc, $dumpMeOnFailure, $moreDiag) = @_; $moreDiag ||= ""; ok($result == 1, $desc) || diag(explain($dumpMeOnFailure), $moreDi +ag); }
Is there some way I can create such an object that wraps Test::More assertion methods and can dynamically set the number of thests, all without losing the Test::More runtime flow?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Wrapping Test::More assertions in Test::More utility classes?
by tobyink (Canon) on Sep 25, 2012 at 16:43 UTC | |
by silkybones (Initiate) on Sep 26, 2012 at 14:29 UTC |