in reply to How to write code tests
Here's a sample test file to test the module X::CSV using Test::Morepackage X::CSV; use strict; use warnings; use Text::CSV; =head1 NAME X::CSV - parse Comma Seperated Value files =head1 SYNOPSIS #create CSV parse my $csvParser = X::CSV->new( data_file => $file_path); eval{ my $data = $csvParser->parse(); }; if($@){ die($@); } sub parse(){ my $self = shift my (@parsed, @csv_source); #open the csv file open(CSV_SOURCE , "<" . $self->data_file) or die "..."; .... .... }
!!@!!#!/usr/bin/perl use strict; use warnings; use X::CSV; #Number of tests use Test::More tests =>3 ; #test 1 & 2 BEGIN { use_ok( 'X::CSV' ); } require_ok( 'X::CSV' ) ; #parse the test.csv my $parser = X::CSV->new( data_file => $ENV{TEST_ROOT}.'/t/test.csv' ); my $result = $parser->parse(); my $length = @{$result}; #test 3 #We have an csv file with 3 rows is($length,'3','We have an sheet with 3 rows');
|
|---|