http://www.perlmonks.org?node_id=529017

gargle has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

How deep into the code should someone test?

I have a base class (of the closure kind, I like my classes like that ;)) with the following protected sub:

# protected add to set credit sub setCreditAmount { my $closure = shift; my $amount = shift; caller(0)->isa(__PACKAGE__) || confess "setCreditAmount is protect +ed"; &{$closure}( "CREDITAMOUNT", $amount ); }

Another class inherits and calls this protected sub setCreditAmount:

# public method to add to the account sub addToAccount { my $closure = shift; my $addAmount = shift; my $amount = $closure->getCreditAmount() + $addAmount; $closure->setCreditAmount($amount); }

addToAccount is public ofcourse and calls setCreditAmount. setCreditAmount can only be called from classes which inherit from the base class. setCreditAmount cannot be reached outside an inherited class.

So how does one unit test this, if at all?

Do you monks consider it overkill? addToAccount gets tested already with all different parameters. I consider addToAccount as a kind of black-box.

What do you Monks think?

Greetings

--
if ( 1 ) { $postman->ring() for (1..2); }