Seeing as much of the stuff I'm going to be doing in future involves testing, I thought I'd look for some tutorial and guides for writing tests.
I found Schwern's very good Test::Tutorial page, which goes a long way to what I wanted but not quite far enough. I basically wanted to write test suites not just for modules but for whole scripts. A mammoth task I know, but but worth it in the long run. But there isn't anything ... except I did discover that Schwern is talking at next week's OSCON and more specifically has a "Writing a Test Library" talk. This sounds exactly what I was after. Only one problem though. I'm can't afford ã2,500 out of my own pocket to go to OSCON :(
I hope Schwern puts his talk online somewhere, or perhaps goes that bit further by writing a book about it all. I enjoyed his talk at last year's YAPC::Europe but at the time didn't have the time to persue it further. I note he's proposed some talks for this years YAPC::Europe, which I hope to be a bit more proactive about this time.
In the meantime, if anyone knows of some good tutorials or guides online, please let me know.
Re:Testing whole scripts
petdance on 2002-07-17T18:41:01
You mean The Perl Review, right?:-) I'm about to roll out some HTML testing stuff today or tomorrow that might be useful, too, along those lines. It'll be wrappers around HTML::Lint.
Maybe we should put up sample code that shows how people use the testing stuff in the real world.
Re:Testing whole scripts
petdance on 2002-07-18T01:39:59
# Here's a sample of a Session.t file that
# corresponds to a Session.pm file I have.
# It could certainly be more robust, and test
# more options than just some simple scalars.
#!/usr/bin/perl -w
use strict;
use constant SAVEPATH=>'/tmp';
use Test::More tests=>7;
BEGIN {
use_ok( 'TW::Session' );
}
my $saved_session_id;
CREATE: {
my $session = new TW::Session( SavePath=>SAVEPATH );
isa_ok( $session, 'TW::Session', 'Created first session' );
$session->{yankee} = 'doodle';
is( $session->{yankee}, 'doodle', 'Stored the value' );
$saved_session_id = $session->id;
}
REREAD: {
my $session = new TW::Session( SID => $saved_session_id, SavePath=>SAVEPATH );
isa_ok( $session, 'TW::Session', 'Instantiated 2nd session instance' );
is( $session->id, $saved_session_id, 'IDs match' );
is( $session->{yankee}, 'doodle', 'Retrieved the value' );
# Check the link method
is( $session->link( 'Click', 'target' ),
"<a href=\"target?SID=$saved_session_id\">Click</a>",
'link() builds correctly' );
my $sess_filename = SAVEPATH . "/sess_$saved_session_id";
$session->delete; # Can't really test this one, but let's clean up anyway.
ok( ! -e $sess_filename, "File $sess_filename was deleted" );
}