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 class
package Service; use base qw/ Test::Class /; use Test::More; sub common_method : Test(1) { my $self = shift; ok (1 == 1, 'common_method'); } 1;
Service_A.pm - Specific to Service A
package 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;
Service_B.pm - Specific to Service B
package 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;
run.t - test script
#!/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.

Update

Problem solved! By using a class variable in the base Service module. This is now accessible from all class instances.


--
Rohan


In reply to Passing data between modules using Test::Class by arc_of_descent

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.