Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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?

In reply to Wrapping Test::More assertions in Test::More utility classes? by silkybones

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others having an uproarious good time at the Monastery: (8)
    As of 2018-04-25 07:53 GMT
    Find Nodes?
      Voting Booth?