If you've not come across them already take a look at Test::Simple, Test::More and Test::Tutorial.
You might also find Test::Class of interest (but since I wrote that one I may be biased :-)
As to what you test - I tend to write all my code "Test First". Basically this means:
- I write the test for what I want my code to do.
This (of course) fails since there isn't any code yet.
- I then write code until my test passes.
- Then, since I know I've finished and can move along to the next piece of functionality that needs testing.
Works very well for me. I get into the coding "flow" much faster this way and end up with very robust code.
Test suites also make changing your code a much less stressful business since you immediately know if you've broken anything.
I always have a window open that sits there doing a make test every time any file in my project changes. Instant feedback. Very handy.
This style comes from Extreme Programming (also known as XP - just be be confusing). If you're interested take a look at extremeprogramming.org.
Retrofitting a test suite on an existing code base can be a much more painful task. Two approaches that have worked for me are:
- Testing the documentation (Test::Tutorial has an example of this).
- Write tests for any bit of code that you need to change. That way you can check that you don't break anything as you make the change, and you will gradually build up a set of tests for the whole code base.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
Outside of code tags, you may need to use entities for some characters:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||