Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: How deep should unit tests go?

by rinceWind (Monsignor)
on Feb 09, 2006 at 09:59 UTC ( [id://529037]=note: print w/replies, xml ) Need Help??


in reply to How deep should unit tests go?

The way of thinking about questions of this nature is in terms of the contract model. If you are delivering a CPAN module, you will be supplying accompanying documentation in the form of POD, documenting the interface. This determines the initial scope for unit tests. Unit tests can be added later for specific bugs that come to light later in the development cycle or after release.

You have chosen to designate setCreditAmount as "protected" - not a concept that Perl has or enforces, though there are probably ways of doing this. Why not make setCreditAmount fully public, documented, and with unit tests?

Alternatively, if you have methods which are "internal", conventionally these are prefixed with an underscore, and are usually not documented in the POD. You could still have unit test calling such methods - sometimes they need to, for simulating aspects of the outside environment.

My criteria for whether unit tests belong with a module distribution are whether they are actually testing something inside the module. The usefulness of unit tests diminishes if they become dependent on code outside the distribution - other modules, and platform or database specific behaviour for example. A better approach is to simulate such external behaviour, using Test::MockObject, DBD::Mock, etc. which will decouple the module from its environment. The DBD::SQLite database is another useful tool here, as you can build cross-platform throwaway databases for running tests against.

Hope this helps

--

Oh Lord, won’t you burn me a Knoppix CD ?
My friends all rate Windows, I must disagree.
Your powers of persuasion will set them all free,
So oh Lord, won’t you burn me a Knoppix CD ?
(Missquoting Janis Joplin)

Log In?
Username:
Password:

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

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

    No recent polls found