Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: How to share an object between test cases using Test::Harness

by psantann (Novice)
on Feb 25, 2011 at 17:34 UTC ( #890197=note: print w/replies, xml ) Need Help??


in reply to Re: How to share an object between test cases using Test::Harness
in thread How to share an object between test cases using Test::Harness

Hi Elisheva, Thank you for this detailed response as well. Currently I'm doing something like that. I have a specific module that handles the object creation and it is called by the test cases. What I wanted to accomplish was that if there is already a connection to my end device and the object already holds all the data I need for further testing, I wanted to leverage this connection and all the existing data, instead of reestablishing the connection and resending setup messages for each test case. Of course each test file will have its share of messages/responses to send and process but there is a subset that is part of the setup that I wanted to avoid repeating. If not only for speed but also to simplify troubleshooting on the device side. Thanks for the tip on done_testing. It does not affect me too much in this case since I'm using TAP::Parser and TAP::Parser::Aggregator to collect my test results but is good to know.
  • Comment on Re^2: How to share an object between test cases using Test::Harness

Replies are listed 'Best First'.
Re^3: How to share an object between test cases using Test::Harness
by psantann (Novice) on Feb 25, 2011 at 23:22 UTC
    After testing a few serialization options including Data::Dumper, Storable and YAML. (Found an interesting article on these and others here:
    http://www252.pair.com/comdog/mastering_perl/Chapters/14.persistence.html)
    I came to the conclusion that the complexity of storing my connection data is not worth the effort ( ran into segmentation faults and other oddities).
    In the end I decided to implement Elisheva's suggestion and run the test cases in a unified form as a single file. That way caching an object became a breeze. Also, I found a way to keep the files separated by making them Perl modules with a single exportable sub that run all tests in that module. A separated file "uses" all the modules and keeps the "memory" of previous tests, and I pass that file to TAP::Parser. Something like this:
    # Main Program ... my $test_file = "MetaTester.pm"; my %args = ( source => $test_file ); my $parser = TAP::Parser->new( \%args ); while ( my $result = $parser->next ) { ... # Then in MetaTester.pm use Test1.pm; use Test2.pm; Test1::run_tests(); Test2::run_tests();
    Thanks again to all that responded.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://890197]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (8)
As of 2018-07-17 12:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (363 votes). Check out past polls.

    Notices?