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ésilets

--- Sample Code:

use strict;

use Test::Unit::TestRunner;
use Test::Unit::TestSuite;
use Test::Unit::TestCase;


package FooBar;
our @ISA = qw(Test::Unit::TestCase);

sub new {
    my ($class, @args) = @_;
    my $self = $class->SUPER::new(@args);
    return $self;
}

sub test_fail {
   my ($self) = @_;
   $self->fail("failed in FooBar.");
}

package FooBar2;
our @ISA = qw(Test::Unit::TestCase);

sub new {
    my ($class, @args) = @_;
    my $self = $class->SUPER::new(@args);
    return $self;
}

sub test_fail {
   my ($self) = @_;
   $self->fail("failed in FooBar2.");
}

package MyTestSuite;
use base qw(Test::Unit::TestSuite);

sub new {
    my ($class) = @_;
    my $self = $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 = Test::Unit::TestRunner->new();
 
########################################################################## 
# 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.
# 
# RESULT:
#    WORKS, BUT ALL ERRORS REPORTED AS THOUGH THEY WERE FROM THE SAME 
#    TEST CASE   
#
# 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 
# use the same methods inherited from a common TestCase subclass.
##########################################################################

#no strict;
#$runner->start(MyTestSuite);
#use strict;

########################################################################## 
# APPROACH 2: Create an empty TestSuite, add TestCases to it and feed it to
#             TestRunner::start()   
#
# RESULT:
#   I get the following error message:
#
#      Couldn't load Test::Unit::TestSuite=HASH(0x18255a4) in any of the 
#      supported ways at ../../../perlib//Test/Unit/Loader.pm line 68.
########################################################################## 

#my $suite = Test::Unit::TestSuite->empty_new();
#no strict;
#$suite->add_test(FooBar);
#use strict;
#$runner->start($suite);


########################################################################## 
# APPROACH 3: Run each TestCase using a different TestRunner.
#
# RESULT:
#     ONLY REPORTS ERRORS FROM THE FIRST TestCase
########################################################################## 

#no strict;
#$runner = Test::Unit::TestRunner->new();
#$runner->start(FooBar);
#print "-- Doing: FooBar2\n";
#$runner = Test::Unit::TestRunner->new();
#$runner->start(FooBar2);
#use strict;


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_idt77&alloc_id492&op=click
_______________________________________________
Perlunit-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/perlunit-users

Reply via email to