in reply to How do i Unit Test a subroutine

If you're asking about testing in general, then see Test::More. Just one recent simple example of many to be found online (many CPAN modules have test suites) is here (although in your case I assume you'd be importing the sub in from a module instead of defining it in the test file itself).

If your question is how to test this specific sub, then it'd be better if you could show the actual code, since this is obviously not it. If you're asking how to test the code with a "fake" database, then perhaps one of the modules Test::MockDBI or DBD::Mock could help (disclaimer: I haven't used them but I've seen them recommended).

Replies are listed 'Best First'.
Re^2: How do i Unit Test a subroutine
by ejvar (Initiate) on Jan 23, 2015 at 11:40 UTC
    This is the actual code
    Package Team use strict: use warnings; use DBI sub get_detail_team{ my ($team,$debug)=@_; my $dbh = connect to databasehandle my sql = get_sql_details($team,$debug) my $sth = $dbh->prepare($sql) $sth->execute() my $result = $sth->fetchall_arrayref(); return get_html_content($result,prama) } sub get_sql_details{ my ($team,$debug) = @_ my sql = "select id ,org,architec from table where team='$team" return $sql } sub get_html_content{ my ($result,$debug) = @_; return '<br><br>Could not locate architects.' if( scalar @$result == 0 + ); my $html =<br> <table> <th>Id</th><th>... foreach my $result_html(@result){ my ($id,$org,$architect) = @result_html $html.= <td>$id>... return $html; }
    this the overview of the code. Now how can we mock this module to test each of the functions.
      Please fix your code tags, your code is quite hard to read. It seems that you probably have the right opening tag, what might be missing is a closing </code> tag at the end of your code snippets.

      Je suis Charlie.