Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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:

  1. I write the test for what I want my code to do.
    This (of course) fails since there isn't any code yet.
  2. I then write code until my test passes.
  3. 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:

  1. Testing the documentation (Test::Tutorial has an example of this).
  2. 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.

In reply to Re: What goes in a test suite? by adrianh
in thread What goes in a test suite? by Marza

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (8)
As of 2024-04-19 14:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found