Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Journal of rob_au (1845)

Friday March 14, 2003
08:32 AM

Testing fun

[ #11032 ]
In writing tests for some production code that I am working on, I have found myself wanting to independently test 'internal' object methods without using the object constructor. The reason for this is because of some of the sorting and queuing methods used within the object are quite extensive with much internal black magic, warranting their own test suite.

In order to solve this problem, I incorporated the following into a test script:

    #   The code braces here are designed to limit
    #   variable scope for some nasty, internal object
    #   method testing - Overt your eyes children before
    #   it takes on its devil form!

    my $obj = bless [ undef, 0, [] ], 'My::Class';


Where the blessed array reference is the same as that blessed in the class constructor. This alternate constructor subsequently allowed the desired testing of internal methods using the $obj object.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • Would you have been better off using Test::MockObject []?

    See also MockObject [].


    • ObjectMother is another good testing pattern to look out for while you're about it. Sample code is in Java, but the idea is good.
    • Thanks for the reply. I have looked at Test::MockObject [] previously and revisited it after reading your post - However, it seems that the real advantage of Test::MockObject [] is fulfilling module dependencies in testing and providing controlled return values from such modules.

      This unfortunately was not the aim of my testing - With the code that I am testing, the standard class constructor builds a very complex queue of child objects from an XML configuration - By default, the enqueue and dequeue methods are