Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

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

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)


In reply to Re: How deep should unit tests go? by rinceWind
in thread How deep should unit tests go? by gargle

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 sharing their wisdom with the Monastery: (2)
As of 2024-04-26 00:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found