UPDATE: I've added two more tests to .t/bo/Rekening.t to check the protected setCreditAmount and setDebetAmount subs (and of course changed the number of tests from 13 to 15

Thanks for the comments and answers :)

I think I'll go with the following (sorry for the dutch names, Passief eq Passive Account and Rekening eq Account (the base class):

I'll implement the wrapper class for testing protected subs later on :)

./t/bo/Passief.t
#!/usr/bin/perl use strict; use warnings; use Math::BigInt; use Test::More tests => 12; use Test::Exception; # We need the Rekening and Actief classes use src::bo::Passief; # we test the passief account my $passief = Passief->new("kapitaal"); is( ref $passief, "Passief", "A passief object" ); is( $passief->getName(), "kapitaal", "It's kapitaal" ); lives_ok { $passief->addToAccount() } "addToAccount is overwritten"; $passief->addToAccount( Math::BigInt->new(5) ); is( $passief->getDebetAmount(), Math::BigInt->new(5), "kapitaal has 5 +credit" ); is( ref $passief->getDebetAmount(), "Math::BigInt", "getCreditAmount() returns a BigInt" ); lives_ok { $passief->subtractFromAccount() } "subtractFromAccount is overwritten"; $passief->subtractFromAccount( Math::BigInt->new(4) ); is( $passief->getCreditAmount(), Math::BigInt->new(4), "kapitaal has 4 + debet" ); is( ref $passief->getCreditAmount(), "Math::BigInt", "getDebetAmount() returns a BigInt" ); is( $passief->balance(), 1, "kapitaal has a 1 balance" ); is( ref $passief->balance(), "Math::BigInt", "balance() returns a BigI +nt" ); # we test if we can call setCreditAmount directly throws_ok { $passief->setCreditAmount(0) } qr/setCreditAmount is prote +cted/, "setCreditAmount is protected"; # we test if we can call setDebetAmount directly throws_ok { $passief->setDebetAmount(0) } qr/setDebetAmount is protect +ed/, "setDebetAmount is protected";
./t/bo/Rekening.t
#!/usr/bin/perl use strict; use warnings; use Math::BigInt; use Test::More tests => 15; use Test::Exception; # We need the Rekening and Actief classes use src::bo::Rekening; # a quick test to see if rekening works my $rekening = Rekening->new("rekeningnaam"); is( ref $rekening, "Rekening", "A rekening object" ); is( $rekening->getName(), "rekeningnaam", "It's rekeningnaam" ); my $zero = Math::BigInt->new(0); is( $rekening->getCreditAmount(), $zero, "kas has 0 credit" ); is( ref $rekening->getCreditAmount(), "Math::BigInt", "getCreditAmount() returns a BigInt" ); is( $rekening->getDebetAmount(), $zero, "kas has 0 debet" ); is( ref $rekening->getDebetAmount(), "Math::BigInt", "getDebetAmount() returns a BigInt" ); # we test a rekening without a name my $rekening2 = Rekening->new(); is( ref $rekening2, "Rekening", "A rekening object" ); is( $rekening2->getName(), undef, "It's undef" ); # we test if we can call addToAccount directly throws_ok { $rekening->addToAccount() } qr/Rekening is a base class/, "addToAccount is protected"; # we test if we can call subtractFromAccount directly throws_ok { $rekening->subtractFromAccount() } qr/Rekening is a base c +lass/, "subtractFromAccount is protected"; # we test if we can call balance directly throws_ok { $rekening->balance() } qr/Rekening is a base class/, "balance is protected"; # we test if we can call setCreditAmount directly throws_ok { $rekening->setCreditAmount(0) } qr/setCreditAmount is prot +ected/, "setCreditAmount is protected"; # we test if we can call setDebetAmount directly throws_ok { $rekening->setDebetAmount(0) } qr/setDebetAmount is protec +ted/, "setDebetAmount is protected"; # magic, we test the setCredit protected sub my $setCredit; my $setDebet; { package Sub::Rekening; our @ISA = 'Rekening'; eval { $rekening->setCreditAmount($two); $rekening->setDebetAmount($one); $setCredit = $rekening->getCreditAmount(); $setDebet = $rekening->getDebetAmount(); }; } is( $setCredit, $two, "setCreditAmount returns 2" ); is( $setDebet, $one, "setDebetAmount returns 1" );
--
if ( 1 ) { $postman->ring() for (1..2); }

In reply to Re: How deep should unit tests go? by gargle
in thread How deep should unit tests go? by gargle

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.