Vienna Perl-QA Hackathon, Day 1

Arrived in Vienna last night and walked across the city center to get to the hotel. It's my second time in Vienna and I love how beautiful it is.

Today I'll be giving some love to Test::Class, Test::Class::Most and (hopefully) TAP::Parser. I've finished the Test::Class work. I had the following output in a test run:

[17:32:26] t/001-test-classes.t .............................. 7983/? #
expected 0 test(s) in setup, 1 completed
[17:32:26] t/001-test-classes.t .............................. 7987/? #
expected 0 test(s) in setup, 1 completed
[17:32:26] t/001-test-classes.t .............................. 7989/? #
expected 0 test(s) in setup, 1 completed

It takes our tests almost an hour to get there, so debugging that is annoying. I've submitted a patch which will add the class name to that warning.

Side note: don't put tests in your test control methods (startup, setup, teardown and shutdown). If something fails in those, your test class probably shouldn't even run. Make 'em assertions instead.

I also plan to add "attributes" to Test::Class::Most so you can do this:

use Test::Class::Most
  parent     => 'My::Test::Class',
  attributes => [qw/customer items/];

sub setup : Tests(setup) {
  my $test  = shift;
  my $schema = $test->test_schema;
  $test->customer( $schema->resultset('Customer')->find({ name => 'bob'}) );
  $test->items( $schema->resultset('Items') );
}

sub some_tests : Tests {
  my $test = shift;
  my $customer = $test->customer;
  ...
}

Basically, I keep seeing test classes where people need data shared across methods and they'll do something like this:

use base 'Some::Test::Class';
my $customer_id = 7;

sub some_tests : Tests {
  my $test = shift;
  my $customer = some_func();
  is $customer->id, $customer_id, '... ack!';   # don't do this!
  ...
}

As from some very annoying timing issues between initialisation and assignment, that's not very OO. How do you inherit $customer_id? You don't. How do you encapsulate that variable? You don't. Adding attributes isn't perfect, but it helps a lot here.

Update: Test::Class::Most 0.05 with attributes is now on the CPAN.

Leave a comment

About Ovid

user-pic Freelance Perl/Testing/Agile consultant and trainer. See http://www.allaroundtheworld.fr/ for our services. If you have a problem with Perl, we will solve it for you. And don't forget to buy my book! http://www.amazon.com/Beginning-Perl-Curtis-Poe/dp/1118013840/