[Perlunit-users] 2 questions: traceback and running test suites and
Status: Beta
Brought to you by:
mca1001
|
From: Desilets, A. <Ala...@nr...> - 2005-06-21 20:29:55
|
Hi all,
I am a newbie to PerlUnit, but have used jUnit and pyUnit extensively.
I have two questions.
First, is there a way to get PerlUnit to print a traceback (with the =
file name and line number of all the function and method calls in the =
call stack) when an exception is raised? This is the default behaviour =
of both jUnit and pyUnit, but it seems PerlUnit only prints the message =
of the exception that was raised. This is sometimes enough to identify =
the source of the problem, but not if the error happens deep inside the =
system.
Secondly, how do you run a suite of tests? I have tried 3 different =
approaches, and none give me exactly what I want. See sample code below =
with inlined comments.
Thx
Alain D=E9silets
--- Sample Code:
use strict;
use Test::Unit::TestRunner;
use Test::Unit::TestSuite;
use Test::Unit::TestCase;
package FooBar;
our @ISA =3D qw(Test::Unit::TestCase);
sub new {
my ($class, @args) =3D @_;
my $self =3D $class->SUPER::new(@args);
return $self;
}
sub test_fail {
my ($self) =3D @_;
$self->fail("failed in FooBar.");
}
package FooBar2;
our @ISA =3D qw(Test::Unit::TestCase);
sub new {
my ($class, @args) =3D @_;
my $self =3D $class->SUPER::new(@args);
return $self;
}
sub test_fail {
my ($self) =3D @_;
$self->fail("failed in FooBar2.");
}
package MyTestSuite;
use base qw(Test::Unit::TestSuite);
sub new {
my ($class) =3D @_;
my $self =3D $class->SUPER::empty_new();
no strict;
$self->add_test(FooBar);
$self->add_test(FooBar2);
use strict;
return $self;
}
sub name { 'My very own test suite' }
package main;
my $runner =3D Test::Unit::TestRunner->new();
=20
########################################################################=
##=20
# APPROACH 1: Implement subclass MyTestSuite of TestSuite, and feed its
# name to TestRunner::start().
# MyTestSuite will wrap a bunch of test cases into a suite.
#=20
# RESULT:
# WORKS, BUT ALL ERRORS REPORTED AS THOUGH THEY WERE FROM THE SAME=20
# TEST CASE =20
#
# I need to see errors from different TestCases, because I often have =
TestCases
# that test different subclasses of a same root class, and these =
TestCases=20
# use the same methods inherited from a common TestCase subclass.
########################################################################=
##
#no strict;
#$runner->start(MyTestSuite);
#use strict;
########################################################################=
##=20
# APPROACH 2: Create an empty TestSuite, add TestCases to it and feed =
it to
# TestRunner::start() =20
#
# RESULT:
# I get the following error message:
#
# Couldn't load Test::Unit::TestSuite=3DHASH(0x18255a4) in any of =
the=20
# supported ways at ../../../perlib//Test/Unit/Loader.pm line 68.
########################################################################=
##=20
#my $suite =3D Test::Unit::TestSuite->empty_new();
#no strict;
#$suite->add_test(FooBar);
#use strict;
#$runner->start($suite);
########################################################################=
##=20
# APPROACH 3: Run each TestCase using a different TestRunner.
#
# RESULT:
# ONLY REPORTS ERRORS FROM THE FIRST TestCase
########################################################################=
##=20
#no strict;
#$runner =3D Test::Unit::TestRunner->new();
#$runner->start(FooBar);
#print "-- Doing: FooBar2\n";
#$runner =3D Test::Unit::TestRunner->new();
#$runner->start(FooBar2);
#use strict;
|