in reply to Re: Unit testing, context and wantarray
in thread Unit testing, context and wantarray

Thanks for your reply.

I think you answer has pointed me in the right direction: I am trying to test for the wrong thing. I should be testing (perhaps via a mock object or similar), that my function does not do anything expensive (e.g., call a database function) to return a result when called in void context. I was erroneously focusing on the return result, rather than the operations of my function. Testing the return value (or lack thereof) would not prove if my function was performing a pointless operation.

Thanks!

  • Comment on Re^2: Unit testing, context and wantarray

Replies are listed 'Best First'.
Re^3: Unit testing, context and wantarray
by GrandFather (Saint) on Aug 13, 2011 at 11:33 UTC

    As a general thing though, one may often call a method in a void context and expect something expensive to happen (connecting to a remote database for example), especially if you use exception handling to manage errors rather than passing error states back.

    True laziness is hard work
Re^3: Unit testing, context and wantarray
by eyepopslikeamosquito (Archbishop) on Aug 13, 2011 at 11:43 UTC

    I should be testing (perhaps via a mock object or similar), that my function does not do anything expensive (e.g., call a database function) to return a result when called in void context.
    Such as playing nethack? :)