Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: TDD of non-module code

by sundialsvc4 (Monsignor)
on Jan 26, 2012 at 14:48 UTC ( #950102=note: print w/ replies, xml ) Need Help??


in reply to TDD of non-module code

AFAIK, Perl doesn’t have an #ifdef capability, which is unfortunate.   I think that you probably are going to have to put the code into modules, unless you merely intend to be doing “black box” regression-testing, because you do need to be able to isolate the functionality that is under test.   But there are real advantages to modularity that have more value than simply to facilitate unit-testing:   modular code is inherently less coupled because there are only a few well-defined “ways in” and “ways out” for each “thing.”   It is the way that I would design such code anyway.


Comment on Re: TDD of non-module code
Re^2: TDD of non-module code
by davies (Vicar) on Jan 26, 2012 at 20:08 UTC

    I don't know what #ifdef does. I suspect it's something to do with C, but unless someone replies saying how it can be emulated in Perl, it doesn't matter. However, I don't see why modules are the only way to isolate functionality. The code I have written is in quite small subs, meaning that the tests that are in the same file are able to test isolated parts. I have, as I mentioned in my OP, extracted some routines to modules and will continue to do this wherever practical.

    Unfortunately, as far as decoupling goes, there are some things that just have to be sequential and coupled. You can't read from an Excel file until you have opened it and you can't do that until you have created an Excel instance. So, while the subs are individually small with only one entry and exit, executing them before their predecessors is implausible. I'm instinctively keen on separating such code that must be coupled from code that need not, and which is in modules already, so if there are arguments against the command line switch approach, I would like to understand them.

    You may be trying to warn me against Moritz's suggestion. If so, please would you be more specific? I haven't tried working out how to implement that yet and would prefer not to try something impossible.

    Regards,

    John Davies

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (13)
As of 2014-09-18 19:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (121 votes), past polls