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:
Corion suggested option 1: and pointed me to his WWW-Mechanize-Chrome's helper.pm testing module. The solution is simple and worth to share (I see # hide from CPAN indexer can some elaborate this?).
Have you other approach? Some quirk I missed? Something to pay attention to?
thanks
L*
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: code duplicate in tests -- code or custom module only needed to test
by hippo (Bishop) on Dec 06, 2018 at 11:51 UTC | |
Re: code duplicate in tests -- code or custom module only needed to test
by haukex (Archbishop) on Dec 06, 2018 at 10:59 UTC | |
Re: code duplicate in tests -- code or custom module only needed to test
by 1nickt (Canon) on Dec 06, 2018 at 13:09 UTC | |
Re: code duplicate in tests -- code or custom module only needed to test
by markong (Pilgrim) on Dec 06, 2018 at 12:33 UTC |