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

In reply to Re: How to write code tests by chanakya
in thread How to write code tests by tcf03

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.