in reply to Philosophical question about testing

Very nice write-up by pemungkah above.

Just wanted to add one more thing: when you challange a test with a lot of different inputs I recommend defining the input and expected output in a data structure, such as an array of hashes like this:

my @tests = ( { desc => "a file with wrong permissions can be repaired", test_file => { { permission => "111", contents => "some string" }, is_valid => 0, is_repairable => 1, }, { desc => "an invalid file that can not be repaired throws an error" + # ADD DATA HERE } );
Now it becomes much easier to test all those different cases in a loop that creates each of those files, gives it the permissions and maybe writes some content into it and then runs the tests for file validity and/or repairability (is that even a word?) on each one in turn without having to copy and paste the test code for each case.
You would feed the is_valid and is_repairable flags into the actual tests to decide which is the correct outcome and the desc would be the description printed by the tests. Adding another case is then as easy as adding another block of definitions to the above datastructure.

Replies are listed 'Best First'.
Re^2: Philosophical question about testing
by rastoboy (Monk) on Nov 01, 2010 at 17:51 UTC
    Wow, LOTS of great feedback, thank you very much quite helpful!