Greg Sabino Mullane wrote: > [1] I've never had a need for random tests myself. The only reason I > break mine apart is to isolate testing various sub-systems, but I almost > always end up having some dependencies put into an early "00" file. I > also tend to a have a final "99" cleanup file. While I could in theory > have each file be independent, in practice it's a lot of duplicated code > and a lot of time overhead, so it's either the 00-99 or (as I sometimes > have done) one giant testing file.
I used to do this with MakeMaker, there was a 00setup.t and a zz_teardown.t. But then when I wanted to run an individual test I had to remember to run 00setup first and teardown after it. Annoying and time consuming. Worse, when doing a full test run if test A failed and screwed up the environment, later tests might fail because of the dirty environment making diagnosing failures difficult. Also if you aborted the test suite in the middle the teardown would not happen leaving a dirty test directory. Since 00setup did not try to teardown first this could lead to setup failing and users reporting the inability to run the test suite. Such a bother. What I did instead is moved all the setup and teardown stuff into simple functions, plopped them into modules in t/lib/ and had each test do: use lib 't/lib'; use MakeMaker::Test; setup_foo(); END { teardown_foo(); } You can even get clever and pack the setup/teardown calls into loading the module so you have even less code per script. Now each test runs independently and cleans itself up.