|Just another Perl shrine|
TDD of non-module codeby davies (Parson)
|on Jan 24, 2012 at 11:12 UTC||Need Help??|
davies has asked for the
wisdom of the Perl Monks concerning the following question:
I'm writing some code that's already over 300 lines long. I'm trying to use TDD and have developed some modules that this code will use. For the modules, the TDD procedure seems obvious to me. Module.pm has an "evil twin" called module.t and invoking perl module.t from the command prompt runs the tests. But I don't see a way to do this with code that isn't in a module.
The sources I have read indicate that the same technique can be applied. I can see that technique working if the code to be run from the command line is quite short and all that is needed is to test outputs against a relatively small number of inputs. However, I am manipulating Excel. Therefore, the first thing I do is to is to open an instance of Excel. It is not my plan to expose that sub to any external code if I can possibly avoid it, but I do want to write the code using TDD. By the same token, the code should not leave an orphaned instance of Excel open, so the approach of having an external .t file could not test that the finished article even opens Excel, because by the end of the code, the instance would be closed.
The approaches I have considered are:
Can anyone suggest anything better, please?