in reply to How to write code tests
It's quite simple. All code starts with a specification (even if just in your head) and some documentation (eg the POD for your module). You write tests to ensure that everything in the spec and the documentation is true. Additionally, once you have written your code you should be aware of where any weak points in it are - where, for example, your off-by-one errors might be lurking - and so you would write extra tests to exercise those bits of the code more thoroughly. It is very important to test and document both for success and for failure. If your docs say that "the age parameter tells how old the person is" then you probably want to test (and document!) what happens when a user enters -1, 1000, and "grapefruit", as well as for reasonable values.
And when you change the code, you of course have updated the docs too, and you add tests to ensure that the updated docs are still true.
|
|---|