I think you may find
Test::Simple and
Test::More helpful. This is the "standard Perl testing" to which
Tanktalus is referring.
The documentation in the above modules will tell you about the mechanics of writing tests. However, a more important issue is deciding what you want to test for. To plan that, you might want to walk yourself through the following steps:
- Organization: organize your code into a form that can be easily tested in parts. Generally, this means moving the subroutines into a module file so that they can be called without causing the main script to be executed in toto. Statements outside of a subroutine get executed each time a script is run, so it is not very friendly to testing things "in parts". (Sorry, I know you were hoping for a different answer)
- Investigation:
- What are the input parameters to SubThatNeedsToBeTested?
- What environmental factors are going to affect the behavior of SubThatNeedsToBeTested?
- For each input parameter, what are the possible legal values? illegal values?
- Does the function have a return value? What is the expected range of values? How should the return value behave in a scalar context? A list context? Is there a difference?
- Does this function have intentional side effects (e.g. modifies global variables, system state)? What are they?
- Development:
- Develop a sample set of inputs - parameters and environmental variables. Make sure to include some with bad values as well as good values
- For each sample set of inputs and calling context, predict the expected output and side effects.
- Now write your script using the various test functions in Test::Simple and Test::More to verify that the actual return values of your function match the expected return values and that the expected side effects actually occur
- Also be sure to include tests with bad inputs to verify that your function behaves as you want it to in the face of bad data.
The above is a very general overview. Perhaps, if you could give us more information about the nature of the function that you are trying to test, we might be able to point you to some additional modules in CPAN that could make your testing life easier. For testing the impact of environmental factors, CPAN has several modules for creating mock environments and mock system components. If your outputs are complicated, there are also numerous modules available for testing and diagnosing errors in complex data structures and long strings.
Best, beth