Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

Ovid
  (email not shown publicly)
http://publius-ovidius.livejournal.com/
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Sunday February 22, 2009
10:09 AM

Making Test::Class More Like xUnit

[ #38529 ]

In xUnit style tests, this is an entire test:

sub first_name : Tests(tests => 3) {
    my $test   = shift;
    my $person = $test->class->new;
    can_ok $person, 'first_name';
    ok !defined $person->first_name,
      '... and first_name should start out undefined';
    $person->first_name('John');
    is $person->first_name, 'John', '... and setting its value should succeed';
}

In the TAP world, we would look at this as three tests, but xUnit says we have three asserts to validate one feature, thus we have one test. Now TAP-based tests have a long way to go before working for xUnit users, but there's one thing we can do. Let's say that you have a test with 30 asserts and the fourth assert fails. Many xUnit programmers argue that once an assert fails, the rest of the information in the test is unreliable. Thus, the tests should be halted. Now regardless of whether or not you agree with this (I hate the fact that, for example, junit requires the test method to stop), you can get this behavior with Test::Class. Just use Test::Most instead of Test::More and put this in your test base class:

BEGIN { $ENV{DIE_ON_FAIL} = 1 }

Because each test method in Test::Class is wrapped in an eval, that test method will stop running and the tests will resume with the next test method.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Patches to the non-existent Test::Class::Cookbook are welcome :-)

    • The reason I'm posting this is because I'm rewriting my Test::Class article. I never published it and now am trying to figure out where. I've also considered putting out a Test::Class::Base module which uses the features I'm describing and makes life just a tad easier for Test::Class users.

      • Super!

        One of the things I'd like to do at the qa-hackathon (assuming nothing more important shows up). Is clear up the T::C internals which... y'know.... suck...

        If the Beeb decides you can go - we should chat.

      • I never published it and now am trying to figure out where.

        If you're still looking for a place, Modern Perl Books is happy to feature guest authors.

        • Is it OK if it's published elsewhere? I've already had someone offer to publish it in another language. I'll need to get their approval if I go that route, though.

          I should probably rewrite the intro if it's for Moderl Perl Books. I'd want to better tailor it for what you're trying to do with that site.