[Purdue-pm] Beginning Perl: testing
Joe Kline
gizmo at purdue.edu
Wed Mar 20 10:21:40 PDT 2013
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 03/20/2013 11:11 AM, Bradley Andersen wrote:
> this is great - but how do we get people to _actually_ make testing a
> serious, full member of their workflow?
>
> _that_ was my question from last week.
Brad,
I'm not sure of a good answer.
We started with one of Dave's modules:
https://gist.github.com/jacoby/5134618
We decided to make some tests for it, inspired by:
http://blogs.perl.org/users/ovid/2013/03/discoverable-tests-and-creating-testing-standards.html
In a directory I created the following dirs:
lib
t
in lib was Beats.pm
in t was Beats.t
Beats.t is:
================================================================
use lib q(/home/jkline/dev/perl/perl-monger/testing-fun/lib);
use Beats;
use Test::Most;
subtest "Verify time_in_beats" => sub {
can_ok 'Beats', 'time_in_beats';
};
subtest "Verify no input return" => sub {
my $return = Beats::time_in_beats();
ok( defined $return, 'defined');
ok( $return > 0, '> 0');
ok( $return < 1000, '< 1000');
};
use DateTime;
my $time = DateTime->now();
subtest "Verify input=now return" => sub {
my $return = Beats::time_in_beats($time);
ok( defined $return, 'defined');
ok( $return > 0, '> 0');
ok( $return < 1000, '< 1000');
};
my $dt = DateTime->new(
year => 1964,
month => 10,
day => 16,
hour => 12,
minute => 00,
second => 00,
nanosecond => 000000000,
time_zone => 'America/Chicago',
);
subtest "Verify input=noon chicago return" => sub {
my $return = Beats::time_in_beats($dt);
is( $return,'750.00','noon chicago=750.00');
};
done_testing;
================================================================
We aren't sure if that's the best way to go but it gives us a start.
- From Ovid's post and script you get a set of tests that at least checks
that all of the subroutines in a module are there.
- From there it's just a matter of adding tests and learning the Test'ing
syntax.
As far as workflow...no clue. I'm still trying to get version control in
my work flow (I beg off as being a sysadmin so most of my stuff is
short...until it's not :-)
joe
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
iEYEARECAAYFAlFJ8CQACgkQb0mzA2gRTpmcUQCcCEQd09VmwmLUX3fGbeyzLoIj
JyIAnRPZGS1Yv2DlDmqBpeNhTwKiBXW+
=UB+j
-----END PGP SIGNATURE-----
More information about the Purdue-pm
mailing list