I'm writing a module that has some functions dealing with text files. I'm new to testing, so I decided to go with Test::More
. Here's how my test file looks like now:
use mymod;
use 5.10.0;
use strict;
use warnings;
use Test::More 'no_plan';
my $file_name = "test.file";
sub set_up {
my $self = shift;
open(my $handle,">",$file_name) or die "could not create file test.file $!\n";
# generate a sample text file here
close($handle);
}
sub tear_down {
my $self = shift;
unlink($file_name) or die "could not delete $file_name $!\n";
}
set_up();
open(my $handle,$file_name) || die "could not open $file_name $!\n";
my @lines = mymod->perform($handle);
is_deeply(\@lines,["expected line","another expected line"]);
close($handle);
tear_down();
Is this a good way of performing tests? Is it ok to deal with generating the sample input file in my test?
By the way, I started writing this as a Test::Unit
test, and then switched to Test::More
. That's why the set_up
and tear_down
functions are there.