Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Testing for Beginners

by halley (Prior)
on Apr 08, 2004 at 13:24 UTC ( #343605=note: print w/ replies, xml ) Need Help??


in reply to Testing for Beginners

You don't have to be "test oriented" to start reaping the benefits of using tests.

Some people use tests to drive design. This is what I would call "test oriented." They first think what the program should do, then they write tests to see if it does it (and doesn't do anything else), then they write the code to do it. In the process of writing the tests, they refine their design before they even get to the actual code. Downside: you have spent a lot of coding time before you get any results, and you scrap a lot of tests as you revise your design.

Some people use tests to drive execution. This is often called "programming by contract." In each subroutine, tests are embedded to ensure that design-time expectations meet run-time reality, at entry and at exit. Downside: performance can suffer, and your subroutines start to look like that old public-speaking maxim: "first you say what you're going to say, then you say what you came to say, then you say what you just said."

You can use tests to drive collaboration and deployment. These are often called "smoke tests." Where there's smoke, there's fire. This is probably the most common in practice. Smoke tests are automatable, and smoke tests can be run without any other knowledge of the application. Include a few test scripts with your new code, and reference those tests in your bug reports. Run the tests before you check in changes to your repository. Run the tests every night by daemon and email the results. Run the tests again whenever you upgrade your computer. Run the tests again when a new operating system is released. Run the tests whenever you are idle. The downsides are, well, you have to actually run the tests, and it's harder to ensure the tests are actually providing meaningful coverage.

--
[ e d @ h a l l e y . c c ]


Comment on Re: Testing for Beginners
Re: Re: Testing for Beginners
by stvn (Monsignor) on Apr 08, 2004 at 21:12 UTC

    The downsides are, well, you have to actually run the tests, and it's harder to ensure the tests are actually providing meaningful coverage.
    If you are at all worried about coverage, try Devel::Cover, it is amazingly helpful. And my personal recommendation is not to read the documentation that comes with it first as it just confuses if you are unfamilair with code coverage tools (as I was). Instead, i recommend just installing it, and running it on one of your test scripts, once you see the output, it will all make a lot more sense.

    -stvn

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://343605]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2014-09-15 05:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (145 votes), past polls