Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re^2: Does anybody write tests first?

by andreas1234567 (Vicar)
on Feb 22, 2008 at 06:32 UTC ( #669529=note: print w/replies, xml ) Need Help??

in reply to Re: Does anybody write tests first?
in thread Does anybody write tests first?

What helped is to move the functionality to modules, because IMHO modules are much neater to test than scripts.
True, but it doesn't have to be like that.

Keep the script, but encapsulate all code in subroutines except the last line below. The last line ensures that one can require the script without actually running its' contents. I argue that this script is no harder to test than a module.

# sub foo { ...; $retval; } sub bar { ...; $retval; } sub main { foo() or die(); bar() or die(); } # Call main only if no stack. Non-empty stack means we're testing. # See chapter 9 of Perl Testing - A Developer's Notebook main() unless caller;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://669529]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2020-01-19 22:27 GMT
Find Nodes?
    Voting Booth?