Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: How to write code tests

by chanakya (Friar)
on Jun 02, 2005 at 08:35 UTC ( [id://462814]=note: print w/replies, xml ) Need Help??


in reply to How to write code tests

Here's a sample module X::CSV. You can check the test script given below to check how the test is implemented.
package 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 "..."; .... .... }
Here's a sample test file to test the module X::CSV using Test::More
#!/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');
!!@!!
May the force be with you

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://462814]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-26 00:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found