Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: Does anybody write tests first?

by andreas1234567 (Vicar)
on Feb 22, 2008 at 11:32 UTC ( [id://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.

# script.pl 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;
--
Andreas

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-04-19 13:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found