Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
The problem is that I have classes that have waaaay more functionality than can be tested in one file. So, the recommended organisation of Foo::Bar::Test testing Foo::Bar isn't going to work.

Yes. I need to explain that better in the documentation. For small simple classes it works well, but if you have multiple fixtures multiple classes make excellent sense.

How does the plan get set in these instances? I can run planless, but I'd prefer not to.

It should "just work". runtests() will tot up the number of expected tests in both objects and output an appropriate plan. The key is to just call runtests() the once.

Also Test::Class explicitly checks the number of tests executed for each test method - so even without a plan you'll get a test failure generated by Test::Class if you run to many / few tests. Since this is happening at the method level this is actually safer than a global plan :-)

Is this a sane use of Test::Class? My only exposure to xUnit has been Rails and the tests I wrote there were variations of the stock test, not anything complex.

What I'd do normally is have a separate subclass for each fixture. So in Test::Class I'd do something like:

{ package Test::Floober; use base 'Test::Class'; use Test::More; sub setup_fixture : Test( setup ) { my $self = shift; @$self{'foo', 'bar'} = ( $self->foo, $self->bar ); } sub foo_and_bar_exist : Test(2) { my $self = shift; my ($foo, $bar) = @$self{'foo', 'bar'}; ok( $foo, "foo is $foo"); ok( $bar, "bar is $bar"); } __PACKAGE__->SKIP_CLASS( 1 ); # prevent abstract class running } { package Test::Floober::FirstFixture; use base 'Test::Floober'; sub foo { 2 }; sub bar { 5 }; } { package Test::Floober::SecondFixture; use base 'Test::Floober'; sub foo { 'abcd' }; sub bar { [ 2..5 ] }; } Test::Class->runtests;

Not that there is anything wrong with your way TIMTOWTDI and all that :-)


In reply to Re: Test::Class and test organization by adrianh
in thread Test::Class and test organization by dragonchild

Title:
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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others musing on the Monastery: (4)
    As of 2014-12-28 20:52 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (182 votes), past polls