|Don't ask to ask, just ask|
Re: Philosophical question about testingby Old_Gray_Bear (Bishop)
|on Oct 28, 2010 at 00:04 UTC||Need Help??|
You said: "Does this make me a bad person?"
Not necessarily bad, just cautious -- it doesn't feel right -- and pragmatic, you went and asked for a second opinion.
When I am writing tests I try as much as possible to get into the 'assertion' mind-set -- is the value returned from my method equal to 'X'? Simple, yes/no tests.
If my method has side-effects (I call it with Y, I get X back, and by the way, the file is now readable....), I'd think about alternative ways of testing my side-effect. Say, create a file without read-permission, call my routine that sorts out the permissions bits to what I want. Then open the file for reading and check the return value from open() ('true' on success, and 'false' on failure). This way you could write a binary test for a successful open. Any function that you can use the or die ... idiom on is susceptible to this approach.
If you haven't run across Ian Langworth and cromatic's book Perl Testing: A Developer's Notebook, you should. They have a number of recipes for testing most everything under the Sun using Perl and the Test Anything Protocol.