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)

Tuesday February 20, 2007
09:15 AM

More Test::Class Fun

[ #32450 ]

In the startup method of my Test::Class base class for my tests, I have the following code:

# the class can be overridden in a subclass
my $class = $test->_class;
unless ($class) {
    $class = ref $test;
    $class =~ s/^Tests:://;
    $test->_class($class);
}

# snip some special case code for traits

$class->require or $test->FAIL_ALL("Could not require $class: $@");

So let's say I have a Customer class. Its corresponding test class is Tests::Customer (this is the only time I use a plural in a package name). This allows my code to automatically load the code I want to test. Today, I just realized I was being foolish by mocking up methods in my classes for every test class, so I just added this to my base class:

sub _mock_class {
    my $test = shift;
    return Test::MockModule->new( $test->_class );
}

Now every test class can easily get a mocked version of the class.

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.