unit test case for this perl code

--0-2074727828-1314953190=:37105
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

Hi I have write the following code and Now I have been asked to write a uni=
t test case for this code. But neither I have=A0 any idea how to write a un=
it test case nor I have ever experience with it. So in this case I am askin=
g your help.=0A=0A#!/usr/bin/perl=0A=0A###=0A## The program is called by ma=
in.pl=0A## dependent conf file is the property.conf located=0A## under the =
config folder in the home directory=0A###=0A=0Ause strict;=0Ause DBI;=0Ause=
File::Basename;=0Ause Cwd qw(realpath);=0A=0Amy $home =3D dirname( realpat=
h( $0 ));=0A=0Amy %config =3D &readConfigFile($home."/config/global.conf");=
=0Amy $db =3D &createDbConnection($config{'user'},$config{'passwd'},$confi g=
{'dbalias'});=0A=0Amy $stmt =3D $db->prepare("select job,OCCURRENCE,retenti=
on_days from CONFIG.PROCESS_LOG");=0A$stmt->execute();=0A=0Amy %prunehash;=
=0Awhile(my [at] row =3D stmt->fetchrow_array) {=0A=A0=A0=A0 $prunehash{$row[0]=
..':~:'.$row[1]} =3D $row[2];=0A}=0A$stmt->finish;=0A=0Aforeach (keys %prune=
hash) {=0A=A0=A0=A0 my ($job,$occ) =3D split(':~:',$_);=0A=A0=A0=A0 my $ret=
days =3D $prunehash{$_};=0A=A0=A0=A0 my $delstmt =3D $db->prepare("delete f=
rom LOG.PROCESS_LOG where days (CURRENT_TIMESTAMP - LOG.PROCESS_LOG.WHEN) >=
".$retdays." and LOG.PROCESS_LOG.JOB =3D '".$job."' and LOG.PROCESS_LOG.OC=
CURRENCE =3D ".$occ." ");=0A=A0=A0=A0 =0A=A0=A0=A0 $delstmt->execute;=0A=A0=
=A0=A0 $delstmt->finish;=0A}=0A=0A=0A$db->disconnect;=0A=0A## SubRoutines.=
=0A=0Asub config {=0A=A0=A0=A0 my ($flname) =3D [at] _;=0A=A0=A0=A0 my %chash;=
=0A=A0=A0=A0 open(FILE, "<$flname") || return 1; # die ("cannot open");=0A=
=0A=A0=A0=A0 # loading conf from file=0A=A0=A0=A0 while (<FILE>) {=0A=A0=A0=
=A0 =A0=A0=A0 chop $_ and next if (/^#/ || $_ eq "\n");=0A=A0=A0=A0 =A0=A0=
=A0 my ($name, $value)=3D/(.*)=3D(.*)/;=0A=A0=A0=A0 =A0=A0=A0 next if ((!$n=
ame) || (!$value));=0A=0A=A0=A0=A0 =A0=A0=A0 $name=3D&trim($name);=0A=A0=A0=
=A0 =A0=A0=A0 $value=3D&trim($value);=0A=0A=A0=A0=A0 =A0=A0=A0 next if (( $=
name eq "") ||( $value eq ""));=0A=A0=A0=A0 =A0=A0=A0 $chash{$name} =3D $va=
lue;=0A=A0=A0=A0 }=0A=A0=A0=A0 close(FILE);=0A=0A=A0=A0=A0 return %chash;=
=0A}=0A=0Asub createDbConnection {=0A=A0=A0=A0 my ($uid,$passwd,$dbalias) =
=3D [at] _;=0A=A0=A0=A0 return DBI->connect ("dbi:DB2:$dbalias", $uid, $passwd)=
or die 'Unable to connect'=0A=A0=A0=A0 =0A}=0A=0Asub trim {=0A=A0=A0=A0 (m=
y $str)=3D( [at] _);=0A=A0=A0=A0 $str =3D~ s/^\s+|\s+$//g;=0A=A0=A0=A0 return $s=
tr;=0A}=0A################################################## ######=0Aglobal=
..conf=A0 contents=0A=0Auser=3D=0A=0Apasswd=3D=0A=0Adbalias=3D=0A=0A=0 AThans=
& Regards in advance=0ARatul.
--0-2074727828-1314953190=:37105--
Anirban Adhikary [ Fr, 02 September 2011 10:46 ] [ ID #2063918 ]

Re: unit test case for this perl code

On Fri, 02 Sep 2011 14:16:30 +0530, anirban adhikary wrote:

> Hi I have write the following code and Now I have been asked to write a
> unit test case for this code. But neither I have=C2=A0 any idea how to =
write
> a unit test case nor I have ever experience with it. So in this case I
> am asking your help.

[Snip program that deletes old records from a database]

If someone used the words "unit test" in a request to you then they
likely have an existing testing environment and expectations of how tests=

should behave and what scope they have. Or is this the first unit test
that the person asking you will have? So find out what "unit test" means=

to them, because there are many possibilities. Assuming they used the
term in its usual sense, this test would be one unit out of many others,
so what do those other tests do, what protocols do they follow, where do
they send their results? Without knowing those things any well-meaning
answers you could get here would probably lead you in the wrong
direction. Tell us what you find out.

--
Peter Scott
http://www.perlmedic.com/ http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=3D0137001274
http://www.oreillyschool.com/certificates/perl-programming.p hp

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Peter Scott [ Sa, 03 September 2011 16:32 ] [ ID #2063942 ]

Re: unit test case for this perl code

On Sep 2, 4:46=A0am, ratul... [at] yahoo.co.in (anirban adhikary) wrote:
> Hi I have write the following code and Now I have been asked to write a u=
nit test case for this code. But neither I have=A0 any idea how to write a =
unit test case nor I have ever experience with it. So in this case I am ask=
ing your help.
>

> Thans & Regards in advance
> Ratul.

What purpose was your code written to perform? Your unit test case
should demonstrate that it performs the function without side effect
or error.

Sayth


--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Sayth Renshaw [ Sa, 03 September 2011 12:28 ] [ ID #2063969 ]
Perl » gmane.comp.lang.perl.beginners » unit test case for this perl code

Vorheriges Thema: Accessing IMap accounts messages via Perl.
Nächstes Thema: oop array question