|Problems? Is your data what you think it is?|
code duplicate in tests -- code or custom module only needed to testby Discipulus (Abbot)
|on Dec 06, 2018 at 10:42 UTC||Need Help??|
Discipulus has asked for the wisdom of the Perl Monks concerning the following question:
I'm writing a lot of test nowadays (finally!) and currently I have a lot of duplicated code in them. This is because I'm testing a simple backup solution and many tests of mines requires backup scenarios to be present in a temporary folder.
So I create and delete files and folders in my tests, I read a write files permissions etc.. and to accomplish these tasks I use CPAN modules not needed by my module but only during tests.
1) I can have a dedicated module with all required modules imported an exposing all subs I need. Where? How? Where the dependencies of this (somehow private module) have to be specified? In the BUILD_REQUIRES in the Makefile.PL of the main module?
2) have a special part of the main module (or a dedicated package?) loaded only during tests? How to trigger this behaviour?
3) (probably worst approach) build only one test file, a big one with all modules used and all subs defined in the very same file
I did not found anything related to the matter (maybe because of generic terms of the search..) nor advice in my bibliotheca and asking in the chatter box I had a precious suggestion by Corion that i'll present below (for future readers) but I also want to know from you other possible approaches or tecniques, and if i missed some detail:
Have you other approach? Some quirk I missed? Something to pay attention to?
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.