Before you decide where your going to put your tests, what in this sample are you going to test?
Can perl invoke a function and assign the values it returns to an array?
Can it then pass a reference to that array to another function?
Someone will say that you should test what happens if the first function returns no files. There are two ways to handle that.
sub extract_file { my( $file_ref ) = @_; while( @$file_ref ) { my $file = shift @$fileref; ## Do stuff } return; }
Note: while not for because the latter will expand the array to a list within the sub, and you've pretty much negated any reason for passing a reference.
my @files = get_xml_files() or die "No XML files to process";
Do we need to test that?
We might run a quick check using the debugger or a repl to ensure that the precedence works. But do we need to re-run that test every time? Is it likely to change?
We could critique this in the basis that it returns a list instead of an array reference.
We could critique it on the basis that substituting a user defined sub for a single call to a built-in is unnecessary.
But is there anything to test here?
Assigning a ref to an array of files, to a scalar called $file could be mildly confusing, but until we see how it is used, it's just nit-picking.
Beyond that, the sub is empty. Can we really apply any tests until we can know what it is going to do?
I appreciate that the snippet is intended to promote replies about how to go about testing a stand alone script, not how to test this particular example. But in the absence of any real code, it is pretty much impossible to suggest good ways of testing.
In reply to Re: Testing A Stand Alone Application
by BrowserUk
in thread Testing A Stand Alone Application
by est
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |