arc_of_descent has asked for the wisdom of the Perl Monks concerning the following question:
Hello,
I'm using Test::Class to organize and run my test suite. I've not found a way to pass data between modules (which are subclasses)
Service.pm - Base test classService_A.pm - Specific to Service Apackage Service; use base qw/ Test::Class /; use Test::More; sub common_method : Test(1) { my $self = shift; ok (1 == 1, 'common_method'); } 1;
Service_B.pm - Specific to Service Bpackage Service_A; use base qw/ Service /; use Test::More; sub method_of_a : Test(1) { my $self = shift; ok (1 == 1, 'method_of_a'); } 1;
run.t - test scriptpackage Service_B; use base qw/ Service /; use Test::More; sub method_of_b : Test(1) { my $self = shift; ok (1 == 1, 'method_of_b'); } 1;
#!/usr/bin/perl use strict; use warnings; use Service_A; use Service_B; Test::Class->runtests();
A good unit testing framework would imply that I test each module independently. But in this particular case, the input for Service_B needs the output of the tests from Service_A. To clarify, I'm running this against a sandbox, and I cannot access Service_B without first initializing and using relevant data from Service_A.
I tried the obvious, i.e. define a foo() accessor in the base Service class, and then use set/get in Service_A/Service_B respectively, but this does not work.
I also tried all possible ways of running the tests as shown in the RUNNING TESTS section of the Test::Class manual.
One way which would work is to write a new module which uses both these services in the same file, but that would involve a lot of cut and paste, and definitely my last resort. The other would be to use some sort of temporary store - like a file or maybe even shared memory.
I was wondering if any of you have come across this problem, and found a way out, preferably using Test::Class and if not, what is the best way to solve this.
Many Thanks.Problem solved! By using a class variable in the base Service module. This is now accessible from all class instances.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Passing data between modules using Test::Class
by adrianh (Chancellor) on Dec 12, 2006 at 18:19 UTC | |
by arc_of_descent (Hermit) on Dec 13, 2006 at 07:31 UTC | |
by adrianh (Chancellor) on Dec 13, 2006 at 10:44 UTC | |
|
Re: Passing data between modules using Test::Class
by pemungkah (Priest) on Dec 13, 2006 at 20:27 UTC | |
by arc_of_descent (Hermit) on Dec 15, 2006 at 09:17 UTC |